Free tools Windows power users keep installed
One-click scans. No signup required.
To show a caption beneath a WordPress post thumbnail (featured image), retrieve the caption saved on that image’s attachment and print it in the relevant post template. In a classic PHP theme, the simplest approach is to call the_post_thumbnail_caption() beside the_post_thumbnail(), while checking that a caption exists before adding a caption element.
How WordPress connects a featured image and its caption
“Post thumbnail” is WordPress’s older term for a featured image: an image assigned to represent a post, page, or custom post type. The featured-image assignment identifies an image attachment; the caption is stored as metadata on that attachment. It is separate from the image’s alt text, title, description, and the post excerpt.
WordPress provides functions to get the featured-image attachment ID and read that attachment’s caption. For the current post, get_the_post_thumbnail_caption() combines those steps and returns an empty string if there is no featured image or its caption is empty. See the WordPress function reference.
Add the caption in a classic theme template
Place the caption output next to the featured-image output in the active theme’s single-post template. The exact template file depends on the theme. The WordPress Theme Handbook’s featured-image guide explains the theme functions used below.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errors#1 Best Overall
- Used Book in Good Condition
<?php if ( has_post_thumbnail() ) : ?>
<?php the_post_thumbnail(); ?>
<?php
$caption = get_the_post_thumbnail_caption();
if ( $caption ) :
?>
<p class="featured-image-caption"><?php echo esc_html( $caption ); ?></p>
<?php
endif;
?>
<?php endif; ?>
The checks serve different purposes: has_post_thumbnail() avoids output when the post has no featured image, while the caption check prevents an empty paragraph when the attachment has no caption. esc_html() is appropriate for displaying the caption as plain text. If you need formatted markup, choose an output and sanitization approach suited to that content rather than treating arbitrary caption text as trusted HTML.
Use the caption output helper or an explicit attachment ID
Shorter helper for the current post
the_post_thumbnail_caption() echoes the current post’s caption and applies the the_post_thumbnail_caption filter first. Use it beside the featured-image call when its output behavior fits your template. See the function reference.
Rank #2
<?php if ( has_post_thumbnail() ) : ?>
<?php the_post_thumbnail(); ?>
<?php the_post_thumbnail_caption(); ?>
<?php endif; ?>
This direct helper call may produce no caption text when none is set. If you require a wrapper only when a caption exists, retrieve the value with get_the_post_thumbnail_caption() and conditionally output the wrapper as in the earlier example.
When the template already has a post ID
For a template or custom code that works with a specific post ID, retrieve the thumbnail attachment ID first and then its caption:
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Rank #3
<?php
$thumbnail_id = get_post_thumbnail_id( $post_id );
$caption = $thumbnail_id ? wp_get_attachment_caption( $thumbnail_id ) : '';
if ( $caption ) {
echo '<p class="featured-image-caption">' . esc_html( $caption ) . '</p>';
}
?>
get_post_thumbnail_id() returns the attachment ID or zero when there is no thumbnail. wp_get_attachment_caption() returns the attachment caption or false on failure. The references are get_post_thumbnail_id() and wp_get_attachment_caption().
Check the active theme before adding code
First inspect the theme’s single-post layout and settings. Some themes may already display a featured-image caption, and adding another output can create a duplicate. Actual placement and display are controlled by the theme and template; WordPress’s function documentation does not establish that every theme displays captions automatically.
Rank #4
If you are developing a theme and the Featured Image interface is missing, declare support in the theme with add_theme_support( 'post-thumbnails' ). The handbook’s featured-image documentation covers this classic-theme mechanism.
Quick Recap
Best Value
Choose the right place for the caption
- Single posts: Add the output near the featured image in the single-post template when readers should see the caption on an individual article.
- Archives or other listings: Add it to the template that renders those views only if captions belong there too; a single-post template change does not automatically place captions everywhere.
- Block-based themes: Find the relevant post template and check its available blocks or settings. The cited PHP-theme documentation does not certify how every block theme handles featured-image captions.
- Plugin route: A plugin may be an alternative if you do not want to edit theme code. A WordPress support discussion mentions this approach, but does not establish the current maintenance or compatibility of a particular plugin. Check its current listing and test it with your theme before relying on it: WordPress support discussion.
When the caption does not appear
- No caption is printed: Confirm that the featured image’s attachment has a caption. The getter reads that attachment field, not alt text, title, description, or post excerpt.
- The image appears but the caption does not: Confirm that the caption code is in the template used by the page you are viewing, and check whether the theme already has a caption setting or output.
- The Featured Image control is unavailable: For a classic theme, check whether it declares
add_theme_support( 'post-thumbnails' ). - The caption appears twice: The theme may already be rendering it. Remove the additional output or disable the existing setting, as appropriate.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.
Recommended Free Tools

