get_the_post_thumbnail_caption() WP 4.6.0
Gets the post thumbnail caption (description).
Use the_post_thumbnail_caption() to display the result.
The caption is specified when editing the image in the admin panel:

Works based on: wp_get_attachment_caption()
Basis of: the_post_thumbnail_caption()
1 time = 0.001914s = very slow | 50000 times = 0.85s = very fast | PHP 7.0.8, WP 4.6
No Hooks.
Return
String. Post thumbnail caption.
Usage
get_the_post_thumbnail_caption( $post );
- $post(int/WP_Post)
- Post ID or WP_Post object.
Default: global $post
Examples
#1 Get a post thumbnail caption
The function will print an empty string if the thumbnail has no caption. Not confuse thumbnail title and thumbnail caption.
echo get_the_post_thumbnail_caption( 6462 );
Changelog
Since 4.6.0 | Introduced. |
Code of get_the_post_thumbnail_caption() get the post thumbnail caption WP 5.6
function get_the_post_thumbnail_caption( $post = null ) {
$post_thumbnail_id = get_post_thumbnail_id( $post );
if ( ! $post_thumbnail_id ) {
return '';
}
$caption = wp_get_attachment_caption( $post_thumbnail_id );
if ( ! $caption ) {
$caption = '';
}
return $caption;
}Related Functions
From tag: caption (of image)
More from tag: Thumbnail (images)
- add_image_size()
- delete_post_thumbnail()
- get_intermediate_image_sizes()
- get_post_thumbnail_id()
- get_the_post_thumbnail()
- get_the_post_thumbnail_url()
- has_image_size()