Tips and tricks

How to Parse Nested Shortcode with the Same Name

Parsing shortcodes such as this one

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

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){
        
        $matches=array();
          $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;
    }
{"type":"main_options","images_arr":"'#ffffff'","enable_ajax":"off","soundcloud_apikey":"","bg_isparallax":"off","bg_slideshow_time":"0","bg_transition":"slidedown","site_url":"https:\/\/digitalzoomstudio.net","theme_url":"https:\/\/digitalzoomstudio.net\/wp-content\/themes\/qucreative\/","blur_ammount":"26","width_column":"50","width_section_bg":"","width_gap":"30","border_width":"0","border_color":"#ffffff","translate_cancel_comment":"Cancel reply","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","content_enviroment_opacity":"30","menu_enviroment_opacity":"70","base_url":"https:\/\/digitalzoomstudio.net"}
{"type":"darkfull"}