I'm using this function to display the caption for featured image:
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])) {
return '<div class="front-caption">'.$thumbnail_image[0]->post_excerpt.'</div>';
} else {
return;
}
}
and I'm using:
the_post_thumbnail_caption();
in the template page to display the caption. I've style the div class "front-caption" with borders. If the caption does not exist it still displays the empty but styled div with borders.
Anyone know how to hide the div if no caption exist?
Thank you in advance.