1

I am retrieving some images post with:

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

How can I retrieve the image title?

Thanks.

1

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.

5
  • 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.
    – Steve
    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
  • 1
    Thanks for the feedback. Still learning the ends and outs here.
    – Steve
    Nov 20 '12 at 18:40
  • Updated to provide more information and hopefully more helpful.
    – Steve
    Nov 20 '12 at 19:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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