wppaste
WordPress

wp_get_attachment_caption( int $post_id = 0 ): string|false

Since
4.6.0
Source
wp-includes/post.php:6903
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:

  1. apply_filters( wp_get_attachment_caption )filterline 6925 (+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

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.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 6.7.7 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.