Title: get_the_post_thumbnail_caption
Published: August 16, 2016
Last modified: May 20, 2026

---

# get_the_post_thumbnail_caption( int|WP_Post|null $post = null ): string

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail_caption/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail_caption/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail_caption/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail_caption/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail_caption/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail_caption/?output_format=md#wp--skip-link--target)

Returns the post thumbnail caption.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail_caption/?output_format=md#parameters)󠁿

 `$post`int|[WP_Post](https://developer.wordpress.org/reference/classes/wp_post/)
|nulloptional

Post ID or [WP_Post](https://developer.wordpress.org/reference/classes/wp_post/)
object. Default is global `$post`.

Default:`null`

## 󠀁[Return](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail_caption/?output_format=md#return)󠁿

 string Post thumbnail caption.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail_caption/?output_format=md#source)󠁿

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

[View all references](https://developer.wordpress.org/reference/files/wp-includes/post-thumbnail-template.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/post-thumbnail-template.php#L297)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/post-thumbnail-template.php#L297-L311)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail_caption/?output_format=md#related)󠁿

| Uses | Description | 
| [wp_get_attachment_caption()](https://developer.wordpress.org/reference/functions/wp_get_attachment_caption/)`wp-includes/post.php` |

Retrieves the caption for an attachment.

  | 
| [get_post_thumbnail_id()](https://developer.wordpress.org/reference/functions/get_post_thumbnail_id/)`wp-includes/post-thumbnail-template.php` |

Retrieves the post thumbnail ID.

  |

| Used by | Description | 
| [the_post_thumbnail_caption()](https://developer.wordpress.org/reference/functions/the_post_thumbnail_caption/)`wp-includes/post-thumbnail-template.php` |

Displays the post thumbnail caption.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail_caption/?output_format=md#changelog)󠁿

| Version | Description | 
| [4.6.0](https://developer.wordpress.org/reference/since/4.6.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_the_post_thumbnail_caption%2F)
before being able to contribute a note or feedback.