the_post_thumbnail_caption()
Displays the post thumbnail caption.
Use get_the_post_thumbnail_caption() to get a caption for further processing in PHP.
The caption is specified when editing the image in the admin panel:

1 time — 0.001038 sec (very slow) | 50000 times — 1.91 sec (fast) | PHP 7.0.8, WP 4.6
Hooks from the function
Return
null
. Nothing (null). Displays the caption.
Usage
the_post_thumbnail_caption( $post );
- $post(int|WP_Post)
- Post ID or WP_Post object.
Default: global $post
Examples
#1 Get post thumbnail caption
The function will print an empty string if the thumbnail has no caption. Not confuse the thumbnail title and thumbnail caption.
<?php the_post_thumbnail_caption( 6462 ); ?>
Changelog
Since 4.6.0 | Introduced. |
the_post_thumbnail_caption() the post thumbnail caption code WP 6.7.2
function the_post_thumbnail_caption( $post = null ) { /** * Filters the displayed post thumbnail caption. * * @since 4.6.0 * * @param string $caption Caption for the given attachment. */ echo apply_filters( 'the_post_thumbnail_caption', get_the_post_thumbnail_caption( $post ) ); }