Skip to content
Advertisement

WordPress get attachment image caption

I tried to get attachment meta caption value as mentioned here, but couldn`t get any output. Other meta arrays like [created_timestamp] or [iso] gave their values.

$img_meta = wp_get_attachment_metadata( $id );
echo $img_meta[image_meta];

This issue happens to both and [title]. Any help is much appreciated.

Advertisement

Answer

The caption and title you are looking to get from wp_get_attachment_metadata are not the title and caption you add in WordPress they are meta data from the actual image itself. To get the WordPress data use something like this (assuming $id is the id of your image).

$image = get_post($id);
$image_title = $image->post_title;
$image_caption = $image->post_excerpt;
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement