wp_get_attachment_caption( int $post_id = 0 ): string|false
- Since
- 4.6.0
- Source
wp-includes/post.php:7043
Retrieves the caption for an attachment.
Parameters
$post_idintoptional- Attachment ID. Default is the ID of the global
$post.Default:0
Return
string|false- Attachment caption on success, false on failure.
Hooks fired · 1
One hook fires while wp_get_attachment_caption() runs, in this order:
- apply_filters( wp_get_attachment_caption )filterline 7065 (+22 into the body)
Filters the attachment caption.
Uses · 2
- get_post()Retrieves post data given a post ID or post object.
- apply_filters()Calls the callback functions that have been added to a filter hook.
Used by · 2
- get_the_post_thumbnail_caption()Returns the post thumbnail caption.
- twenty_twenty_one_post_thumbnail()Displays an optional post thumbnail.
Source
function wp_get_attachment_caption( $post_id = 0 ) { $post_id = (int) $post_id; $post = get_post( $post_id ); if ( ! $post ) { return false; } if ( 'attachment' !== $post->post_type ) { return false; } $caption = $post->post_excerpt; /** * Filters the attachment caption. * * @since 4.6.0 * * @param string $caption Caption for the given attachment. * @param int $post_id Attachment ID. */ return apply_filters( 'wp_get_attachment_caption', $caption, $post->ID );}History
Introduced in 4.6.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.0.4 tag, from
src/wp-includes/post.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.