wp_get_attachment_caption

The timeline below displays how wordpress function wp_get_attachment_caption has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 5.7

/**
 * Retrieves the caption for an attachment.
 *
 * @since 4.6.0
 *
 * @param int $post_id Optional. Attachment ID. Default is the ID of the global `$post`.
 * @return string|false Attachment caption on success, false on failure.
 */
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);
}

WordPress Version: 5.3

/**
 * Retrieves the caption for an attachment.
 *
 * @since 4.6.0
 *
 * @param int $post_id Optional. Attachment ID. Default is the ID of the global `$post`.
 * @return string|false False on failure. Attachment caption on success.
 */
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);
}

WordPress Version: 4.6

/**
 * Retrieves the caption for an attachment.
 *
 * @since 4.6.0
 *
 * @param int $post_id Optional. Attachment ID. Default is the ID of the global `$post`.
 * @return string|false False on failure. Attachment caption on success.
 */
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);
}