wp_get_attachment_caption() – Retrieves the caption for an attachment.

You appear to be a bot. Output may be restricted

Description

Retrieves the caption for an attachment.

Usage

$string|false = wp_get_attachment_caption( $post_id );

Parameters

$post_id
( int ) optional – Optional. Attachment ID. Default is the ID of the global `$post`.

Returns

string|false Attachment caption on success, false on failure.

Source

File name: wordpress/wp-includes/post.php
Lines:

1 to 24 of 24
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 );
}
 

 View on GitHub View on Trac