wp_get_attachment_caption() WP 1.0
Retrieves the caption for an attachment.
✈ 1 time = 0.000544s = slow | 50000 times = 0.36s = very fast | PHP 7.0.8, WP 4.6
Hooks in function
Return
String/false. False on failure. Attachment caption on success.
Usage
wp_get_attachment_caption( $post_id );
- $post_id(int)
- Attachment ID.
Default: ID of the global $post
Code of wp get attachment caption:
wp-includes/post.php
VER 5.0.3
<?php
function wp_get_attachment_caption( $post_id = 0 ) {
$post_id = (int) $post_id;
if ( ! $post = get_post( $post_id ) ) {
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 );
}
Related Functions
More from category: Images