get_the_post_thumbnail_caption() WordPress Function

The get_the_post_thumbnail_caption() function is used to retrieve the caption for a post thumbnail. This function will return an empty string if there is no caption for the thumbnail.

get_the_post_thumbnail_caption( int|WP_Post $post = null ) #

Returns the post thumbnail caption.


Parameters

$post

(int|WP_Post)(Optional) Post ID or WP_Post object. Default is global $post.

Default value: null


Top ↑

Return

(string) Post thumbnail caption.


Top ↑

Source

File: wp-includes/post-thumbnail-template.php

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;
}


Top ↑

Changelog

Changelog
VersionDescription
4.6.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.