I’ve created my own theme based on a very lean template. My theme is not parsing the ...
markup to the correct html. It’s just showing the text without any markup around it. Here are the relevant observations for my situation:
- When editing the post it shows
...
in “Text” mode, and a nice image with caption in “Visual” mode. (as expected) - If I view the post (single) it just renders an
<img .../>
tag and the caption text as plain text. - If I view the post (single) in theme TwentyEleven it does render the caption text in a special tag
<p class="wp-caption-text">my caption</p>
. This is what I’m after in my own theme.
That last observation seems important, and should be my lead to the solution. I’ve dug through the TwentyEleven theme and found that it renders the content the same way as my own theme does:
<?php the_content(); ?>
I’ve opened and searched through all the TwentyEleven files, but could not find “wp-caption” anywhere important, or any other clue as to how TwentyEleven gets WordPress to parse the captions and render them with special markup.
I’ve gone through the functions.php file in TentyEleven because my instinct told me that’s where the theme might register a hook or filter for parsing shortcode, but I couldn’t find anything.
In addition, I’ve tried the following:
echo apply_filters('the_content', get_the_content());
echo do_shortcode(get_the_content());
But neither gives the desired result.
So, the question is: How does a theme get WordPress to parse captions and render them in special markup?
That
caption
shortcode is built into WordPress. It should generate the same markup for any theme, unless the theme or a plugin has unregistered it and registered a replacement. I don’t know if that is the case with your theme or with TwentyEleven. Look for ‘img_caption_shortcode’ in your theme files, probablyfunctions.php
. If your theme is unregistering it, you should seeremove_shortcode('img_caption_shortcode');
somewhere.The CSS, and hence the appearance of the processed shortcode, will almost certainly vary theme to theme.