wp_get_attachment_caption( int $post_id )

Retrieves the caption for an attachment.


Description Description


Parameters Parameters

$post_id

(int) (Optional) Attachment ID. Default is the ID of the global $post.


Top ↑

Return Return

(string|false) False on failure. Attachment caption on success.


Top ↑

Source Source

File: wp-includes/post.php

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

Top ↑

Changelog Changelog

Changelog
Version Description
4.6.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.