A WordPress-centric search engine for devs and theme authors



wp_get_attachment_caption ›

Since4.6.0
Deprecatedn/a
wp_get_attachment_caption ( $post_id = 0 )
Parameters:
  • (int) $post_id Optional. Attachment ID. Default is the ID of the global `$post`.
    Required: No
    Default:
Returns:
  • (string|false) False on failure. Attachment caption on success.
Defined at:
Codex:

Retrieves the caption for an attachment.



Source

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