## images – Show div if it exists other wise no should be displayed in HTML

Question

I am learning PHP and I am trying to add on featured images. However, if the has not be specified on an image, I don’t want to display in the HTML. Currently the code always outputs in HTML whether it has been set or not.

Any help would be much appreciated. Thanks.

     function get_caption_and_desc_post_image() {
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 '<figcaption>'.$thumbnail_image[0]->post_excerpt.'</figcaption> <div class="image-
description">'.\$thumbnail_image[0]->post_content.'</div>';
}
else {
return;
}
}