Nested Shortcode Detection

From: http://codex.wordpress.org/Shortcode_API#Limitations

The shortcode parser correctly deals with nested shortcode macros, provided their handler functions support it by recursively calling do_shortcode()

It will not let you nest the same shortcode inside another though:

However the parser will fail if a shortcode macro is used to enclose another macro of the same name

Assuming you won’t be doing so, here is a contrived example of what you need to do in your shortcode callback:

function paragraph_wrap($atts, $content) {

     // if there are nested shortcodes - handle them
     $content = do_shortcode($content);

     // wrap content in a paragraph tag
     $paragraphed = '<p>' . $content . '</p>';

     return $paragraphed;
}
add_shortcode('wrap_p', 'paragraph_wrap');

Hope this helps.

Leave a Comment