How can I get the title attribute from get_the_post_thumbnail()?

In my theme I want to display the featured image, but I also want to display the title attribute (of the image, not of the post/page) beside the image itself.

Is there a simple way to do this? Where should I be looking?

Read More

Thanks,
John.

Related posts

Leave a Reply

4 comments

  1. post_excerpt is actually the caption attribute. Here is the correct answer:

    $title = get_post(get_post_thumbnail_id())->post_title; //The Title
    $caption = get_post(get_post_thumbnail_id())->post_excerpt; //The Caption
    $description = get_post(get_post_thumbnail_id())->post_content; // The Description
    
  2. Since WordPress 4.6 there are new functions for the post thumbnail caption

    Get caption text: (Doc link)

    // return the caption text without any html markup
    get_the_post_thumbnail_caption();
    

    Output caption text: (Doc link)

    // echo the caption text without any html markup
    the_post_thumbnail_caption();
    

    You can add a specific post as object or id as parameter. Without (like shown above) WordPress uses the current post.