Captions in wordpress do not support nested shortcodes at the moment (v3.6
). So, If I do write
<img src=""> I love my [city]
Where city is suppose to be processed but it does not. How do I fix this?
Ticket: #24990
Captions in wordpress do not support nested shortcodes at the moment (v3.6
). So, If I do write
<img src=""> I love my [city]
Where city is suppose to be processed but it does not. How do I fix this?
Ticket: #24990
Comments are closed.
There is a hook inside the caption shortcode that will allow you to hijack the whole thing. Most of the following is copied from the Core
img_caption_shortcode
function.The latest versions of WP have really improved the filterability of caption arguments, so I think this new answer will have the smallest footprint and safest operation.
What we need to do is directly filter
$atts['caption']
duringshortcode_atts()
for the[caption]
shortcode. We can do this with theshortcode_atts_caption
filter which only affects the caption shortcode.As a bonus I added a commented-out line that will test the caption for a specific shortcode before running
do_shortcode()
. This is useful if you only want to enable a particular shortcode in captions (I use it to enable only the Shortcode Shortcode). Careful though:do_shortcode()
will process all shortcodes, not just the one you tested for.Using latest function
has_shortcode()
introduced onv3.6
This solution can be used on any third party shotcode that didn’t implemented nested shortcode support.
Any better solution welcomed!