Nesting Shortcodes in WordPress (shortcodes in shortcodes)

Shortcodes in WordPress that are available in CollectiveRay.com are extreamly usefull for applying formatting or embeding external content in your pages or posts.
The only problem with them is the parser only does a single pass on the content, so if your shortcodes outputs a shortcode, or you have a shortcode nested within shortcodes, they wont render.

I found on the WordPress Codex that, to enable nesting shortcodes, or shortcodes within shortcodes, I would have to add return do_shortcode($content); This way it will push the result back into the parser.

That’s all very well, but what of shortcodes I didn’t make, or don’t have this added to them? So I made a little plugin that would override the default do_shortcode filter with an evaluator that would check for shortcodes and keep pushing it to do_shortcode until they are all done.

/*
Plugin Name: Shortcode Recursion
Description: Adds shortcode recursion for shortcodes that have shortcodes in shortcodes that has a shortcode in a shortcode in a shortcode with a shortcode in it, all wrapped in a shortcode within a shortcode... and so on.
Author: David Cramer
Version: 1.0
Author URI: http://digilab.co.za/
*/

/* evaluates content for shortcodes and sends it to do_shortcode() if needed and revaluates the result */
function shortcode_inception($content){
    // evaluate content for shortcodes.
    preg_match_all("/".get_shortcode_regex()."/s", $content, $matches);
    // if has shortcode, return revaluated content from  native do_shortcode
    if(isset($matches[2][0]))
        return shortcode_inception(do_shortcode($content));
    // return if nothing is found
    return $content;
}
// remove the native do_shortcode filter
remove_filter('the_content', 'do_shortcode', 11);
// replace the filter with the evaluator function
add_filter('the_content', 'shortcode_inception', 11);  

Comments

9 responses to “Nesting Shortcodes in WordPress (shortcodes in shortcodes)”

  1. The Betking app is super convenient! Makes betting on the go a breeze. Download it and see for yourself: betking app

  2. Decided to give 78wint01 a shot based on what I saw on 78wint01.com. Not bad! Graphics are decent, and I actually managed to win something . Maybe luck, maybe something else… go see: 78wint01

  3. Alright mates, just had a crack on 79winbet. Not bad, not bad at all. Definitely worth a punt if you’re looking for a new place to put your bets. Check it out: 79winbet

  4. Gotta respect PAGCOR for keeping things regulated. Makes you feel a bit safer when you’re playing. It is what it is. Explore the possibilities pagcor

  5. VIPPH1 is similar enough in what the other one does. I would check this out too if you want. Checkout vipph1

  6. Been playing on 88clbantoan for a bit now. It’s pretty solid, good selection of games, and I haven’t had any major issues. Could use a little refresh on the design, but overall, a decent place to have some fun. Check it out at 88clb8gq com

  7. M999app – the app is convenient to use, makes it easy to play on the go. Not the prettiest design, but gets the job done. Download and enjoy here: m999app

  8. Yo, 1010betlogin is my go-to spot these days. Super easy to navigate, and I always find what I’m looking for. Check it out 1010betlogin, you might like it.

  9. Heard some buzz about 252betapp, so I checked it out. Not bad, pretty straightforward. My thoughts 252betapp.

Leave a Reply

Your email address will not be published. Required fields are marked *