WordPress at a glance

the_post_thumbnail_caption() WP 4.6.0

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.001038s = very slow | 50000 times = 1.91s = fast | PHP 7.0.8, WP 4.6
Hooks in function
Return

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 ); ?>

Code of the post thumbnail caption: wp-includes/post-thumbnail-template.php VER 5.1.1

<?php
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 ) );
}

Related Functions

From tag: Thumbnail (images)

More from category: Thumbnails

No comments
    Hello, !     Log In . Register