Plugin Planet

Premium WordPress Plugins

USP Pro is equipped with a powerful set of shortcodes that enable vast configurational possibilities, including wrapping a shortcode with a shortcode, aka nested shortcodes. In this post, we’ll provide an example and a quick solution for getting WordPress to recognize and execute shortcodes within shortcodes when included in post/page content and/or widgets.

Enable nested shortcodes

Super easy, just add the following lines to your theme’s functions.php file:

// execute shortcodes in content and widgets
add_filter('the_content', 'do_shortcode', 10);
add_filter('widget_text', 'do_shortcode', 10); 

That’s all there is to it. The first add_filter enables nested shortcodes in post/page content, and the second add_filter enables same in widgets. Feel free to remove either if not needed. Once that code is in place, you can do cool stuff like use shortcodes to display forms only to logged in users, like so:

[usp_member][usp_form id="register"][/usp_member]

Related: