I have used this code in my page content to try and output an image + caption with a custom caption class and id...

[caption id="my-caption-id" class="my-caption-class" align="alignnone" width="399"]<img src="whatever.jpg" alt="whatever" width="399" height="600" /> My caption text[/caption]

...but the caption's id and class names are not being output.

After some digging around, I found the img_caption_shortcode function in wp-includes/media.php which handles the id and class attributes of the [caption] shortcode but, after some experimenting, it seems this function is not executed with the [caption] shortcode...

So does anyone know which function the [caption] shortcode is linked to? (and / or how to get the class and id attributes to be output on a caption?)

I'm using WordPress 3.9.2 .


You should try this on a default theme (without any plugins), to see if that makes any difference.

Your shortcode example:

[caption id="my-caption-id" class="my-caption-class" align="alignnone" width="399"]
    <img src="whatever.jpg" alt="whatever" width="399" height="600" /> 
    My caption text

gives this output:

<div id="my-caption-id" 
     style="width: 409px" 
     class="wp-caption alignnone my-caption-class">
    <img src="whatever.jpg" alt="whatever" width="399" height="600">
    <p class="wp-caption-text">My caption text</p>

on the Twenty Twelve theme. It's just a little bit formatted to make it easier to read here.

So the caption id and classes are displayed in the output.


It looks like your theme is overriding the image caption via:

// Remove default inline style of wp-caption
add_shortcode('wp_caption', 'fixed_img_caption_shortcode');
add_shortcode('caption', 'fixed_img_caption_shortcode');

in the /library/cleanup.php file.

  • Of course. Thank you. I am using the FoundationPress theme. I'm pretty sure that will be overriding the shortcode function. – ban-geoengineering Aug 21 '14 at 10:14
  • 1
    I think I found the overriding image caption code within your theme. Please check out the updated the answer. – birgire Aug 21 '14 at 10:19
  • 1
    Thanks. I've just submitted a Pull Request that corrects this - github.com/olefredrik/FoundationPress/pull/98 – ban-geoengineering Aug 22 '14 at 17:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.