wordpress snippets last updated   : August 18, 2014
we now have 638 snippets

Featured / post thumbnail image caption

wordpress snippet

Add the first block of code to the functions.php of your wordpress theme, then add the second block within the loop of the desired template file, single.php or, index.php to display featured image caption.

snippet :  PHP - functions.phpcopy
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>';
  }
}
snippet :  PHPcopy
<?
        the_post_thumbnail_caption();
?>

Did you like this post? If so please share it with your friends. Thanks!

jqsnipp.com | we just launched jquery snippets website