On this page
wp_get_attachment_caption( int $post_id ): string|false
Retrieves the caption for an attachment.
Parameters
$post_idint Optional-
Attachment ID. Default is the ID of the global
$post.
Return
string|false Attachment caption on success, false on failure.
Source
File: wp-includes/post.php. View all references
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 );
}
Hooks
- apply_filters( 'wp_get_attachment_caption',
string $caption ,int $post_id ) -
Filters the attachment caption.
Related
Uses
| Uses | Description |
|---|---|
| apply_filters() wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. |
| get_post() wp-includes/post.php | Retrieves post data given a post ID or post object. |
Used By
| Used By | Description |
|---|---|
| get_the_post_thumbnail_caption() wp-includes/post-thumbnail-template.php | Returns the post thumbnail caption. |
Changelog
| Version | Description |
|---|---|
| 4.6.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_get_attachment_caption