get_the_post_thumbnail_caption()
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:
Used By: the_post_thumbnail_caption()
1 time — 0.001914 sec (very slow) | 50000 times — 0.85 sec (very fast) | PHP 7.0.8, WP 4.6
No Hooks.
Returns
String. Post thumbnail caption.
Usage
get_the_post_thumbnail_caption( $post );
- $post(int|WP_Post|null)
- 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. |
get_the_post_thumbnail_caption() get the post thumbnail caption code WP 7.0
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;
}