WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am retrieving some images post with:

$img = wp_get_attachment_image_src( $attachment_id, 'full' );

How can I retrieve the image title?


share|improve this question
up vote 1 down vote accepted

In WordPress attachments are stored as posts so you can use most of the post specific WordPress calls and functions to read/write data associated with the attachment. This applies to post meta data for an attachment as well.

So in this case, since you have the post ID ( same as $attachment_id ) you can simply use the get_the_title() function:

$sImageTitle = get_the_title( $attachment_id );

This returns a string of the post's title for the given post ID.

See more info. at the codex docs here.

share|improve this answer
Stephen, at least link the function name to the Codex. meta.stackexchange.com/q/7656 – brasofilo Nov 20 '12 at 18:17
Thanks, I typically do but missed it this time. I've edited my answer to add the link. – Stephen Nov 20 '12 at 18:20
Check toscho's comment to this Answer. I'm writing this comment on the Low Quality queue... – brasofilo Nov 20 '12 at 18:37
Thanks for the feedback. Still learning the ends and outs here. – Stephen Nov 20 '12 at 18:40
Updated to provide more information and hopefully more helpful. – Stephen Nov 20 '12 at 19:04

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.