I know it is possible to nest shortcodes if they use the do_shortcode wrapper, however, the codex states:
“However the parser will fail if a shortcode macro is used to enclose another macro of the same name:”
Is there a way around this?
for example if I have the a shortcode to make a div such as:
[div]some content in a div[/div]
I want to be able to use:
[div]
[div]a nested div[/div]
[/div]
but this will fail with the standard do_shortcode wrapper.
My temporary workaround is the duplicate the shortcode with _parent appended to the name but than I can only nest 1 level deep unless I created div_parent1, div_parent2 etc…
If you are writing the shortcode there is a simple solution. You can write several shortcodes that call the same function. I have shortcodes for creating html blocks such as divs, and have several with names like div, block1, block2 eg.
They all call the same function. They can be nested as long as you remember to use different short codes.
The WordPress short code support suffers from the attempt to do the parsing with regex only. It is possible to do this sort of parsing with a mixture of regex, a finite state machine, and a stack. That approach can handle nesting and can be very fast, especially when there are very few shortcodes. Every time I encounter this I’m tempted to give it a try.
The API tells it like it is, thus this is not possible:
This is a limitation of the context-free regexp parser used by do_shortcode() - it is very fast but does not count levels of nesting, so it can't match each opening tag with its correct closing tag in these cases.
The functions in question in the latest version (3.4.2) are:
You need to do the shortcodes again for the content in your shortcode. Example:
See as well: What is the best way to enable nested shortcodes? (WordPress SE)
Just seeing: This does not solve the problem in WordPress so does not answer your question. I thought it would have been fixed that until now.