How to Parse Nested Shortcode with the Same Name

Parsing shortcodes such as this one

    [col size="6"]...[/col]
    [col size="6"] // second col
            [col size="6"]...[/col] // second col end, wrong
            [col size="6"]...[/col]

can be tricky because the second [col] is ended by the one nested in the second, nested [row]

so I have found that the best solution is to parse the second [row] first , before the first [row]

just add a the_content filter

add_filter( "the_content", 'parse_content_for_nested_shortcodes' ); 

and this is the function

function parse_content_for_nested_shortcodes($content){
          $subject = $content;
$pattern = '/[row.*?([row.*?].*?[/row])/';
preg_match_all($pattern, $subject, $matches);
if(count($matches)>0 && isset($matches[1])){
    foreach($matches[1] as $regmatch){
        $content = str_replace($regmatch, stripslashes(do_shortcode($regmatch)), $content);

        return $content;

  • tom
    August 2, 2014 at 12:12 pm

    hello, i’ve bought dzscalendar plugin. I have a problem how to use calendar in header (shortcode not work) ?
    i tried to use :

  • bluebusinessdialog
    March 19, 2015 at 10:30 pm

    I¡¦m not positive where you are getting your information, however good topic. I needs to spend some time learning much more or working out more. Thanks for excellent info I used to be searching for this information for my mission.

  • freedomteamautogroup
    June 3, 2015 at 6:54 am

    Hey very nice web site!! Man .. Excellent .. Amazing .. its a really great blog post of i enjoyed lot.thanks again for share with us.

  • boisefoodstorage
    June 3, 2015 at 6:59 pm

    I simply want to mention I’m beginner to blogging and really liked this website. Very likely I’m likely to bookmark your site . You surely come with tremendous well written articles. Cheers for sharing your blog site.

  • ny-businesslaw
    June 7, 2015 at 11:49 am

    Your mode of telling all in this paragraph is genuinely pleasant, all be capable of without difficulty understand it, Thanks a lot.

Leave a comment

Your email address will not be published

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

+ 65 = 75

{"type":"main_options","images_arr":"'#ffffff'","enable_ajax":"off","soundcloud_apikey":"","bg_isparallax":"off","bg_slideshow_time":"0","bg_transition":"slidedown","site_url":"http:\/\/","theme_url":"http:\/\/\/wp-content\/themes\/qucreative\/","blur_ammount":"26","width_column":"50","width_section_bg":"","width_gap":"30","border_width":"0","border_color":"#ffffff","translate_leave_a_comment":"Leave a comment","translate_leave_a_comment_to":"Leave a comment to","is_customize_preview":"off","width_blur_margin":"30","gallery_w_thumbs_autoplay_videos":"off","enable_native_scrollbar":"on","content_enviroment_opacity":"30","menu_enviroment_opacity":"70"}