I am trying to call shortcodes recursively. The idea is to use shortcodes within a shortcode, I tried exploding the string tried some other logics but none worked.
Can you please help.
I'll share an example below.
add_shortcode( 'first', function ( $attr ) {
return 'First ' . $attr['key1'] . ' ' . $attr['key2'];
} );
add_shortcode( 'second', function ( $attr ) {
return 'Second ' . $attr['key1'] . ' ' . $attr['key2'];
} );
add_shortcode( 'third', function ( $attr ) {
return 'Third ' . $attr['key1'];
} );
Now suppose the string is $string = '[first key1="[second key1="abcd" key2="shortcode"]" key2="[third key1="shortcode"]"]';
OR $string = '[first key1="[second key1="abcd" key2="[third key1="shortcode"]"]" key2="[third key1="shortcode"]"]';
Now most probably the output for first string should be something like this: 'First Second abcd shortcode Third shortcode'
And for the second one should be something like this: 'First Second abcd Third shortcode Third shortcode'
But I am not getting the result. Can someone help me to create a function which takes a string and recursively checks for the shortcode and then execute them (do_shortcode).