Home / functions.php / Creating nested shortcode concept
  • How to Creating nested shortcode concept


    Surely I’m not the first but after recently being asked by a visitor about nested shortcodes I figure I would fool around with the idea. Adding this snippet to the functions.php of your wordpress theme will let you fool around with the following nested shortcode [link][my_text][/link]. No tricks just pass $content into do_shortcode() and works like a charm.

    ( click code to copy )

    wordpress snippet : PHP

    add_shortcode("my_text", "my_text");
    function my_text() {
    	return 'nested shortcode';
    function my_link($atts, $content = null) {
    		"href" => 'http://'
    	), $atts));
    	return '<a href="'.$href.'">'.do_shortcode($content).'</a>';
    add_shortcode("link", "my_link");
    ( click code to copy )

    wordpress snippet : SHORTCODE


    ( WordPress codex functions, hooks, in this snippet. )

    add_shortcode, do_shortcode, shortcode_atts,
  • Ronny

    Thanks for this tip but if i may ask, what use can this nested shortcode be put to? I mean in what ways and how can it be used?