Featured image - Display image caption (4 posts)

  1. kfallman
    Posted 5 years ago #

    I print out the "featured image" ( the_post_thumbnail ) on single.php, how do i display the image caption, and perhaps image description ?

  2. kfallman
    Posted 5 years ago #

    Found this: http://core.trac.wordpress.org/ticket/12235
    And this: http://wordpress.org/support/topic/display-caption-with-the_post_thumbnail?replies=10

    Seems like there is no ready to use vars, you have to use own skills.

    Anyway, i used this from second link and it worked

    function the_post_thumbnail_caption() {
      global $post;
      $thumbnail_id    = get_post_thumbnail_id($post->ID);
      $thumbnail_image = get_posts(array('p' => $thumbnail_id, 'post_type' => 'attachment'));
      if ($thumbnail_image && isset($thumbnail_image[0])) {
        echo '<span>'.$thumbnail_image[0]->post_excerpt.'</span>';
    Usage - the_post_thumbnail_caption();
  3. debart
    Posted 5 years ago #

    Thanks for posting this. Very helpful.

  4. Ben Hutchings
    Posted 5 years ago #

    Perfect! Thanks for gathering the info.

Topic Closed

This topic has been closed to new replies.

About this Topic