Show description and caption of the featured image in Wordpress

featured image caption and description in wordpress
Do you want to show description of the featured image in WordPress? For example on the homepage?
 
Well, all you have to do is use this code:
----------------------------------------------------------------------
<?php
echo '<div class="re-featured-image">';
the_post_thumbnail();
echo '<div class="re-featured-image-description">' . get_post(get_post_thumbnail_id())->post_content . '</div>';
echo '</div>';
?>
---------------------------------------------------------------------

Where you must to paste this code? Depends where you want to display the image with the description. To the homepage, file is usually the index.php; for the article, the file is single.php.

Going into "technical", I use the function get_post() to retrieve information of the image (i pass the id of featured image).

The description of the image is saved as a post-content, so I'm going to read this information and show it in a div (but you might as well put it in a span) assigning the class "re-featured-image-description", so that you can configure the graphic using the style.css file.

The description is not enough for you? Here is how to show the caption of the highlights image:

------------------------------------------------------------------
<?php
echo '<div class="re-featured-image">';
the_post_thumbnail();
echo '<div class="re-featured-image-caption">' . get_post(get_post_thumbnail_id())->post_excerpt . '</div>';
echo '</div>';
?>
--------------------------------------------------------------------

Still using get_post(), I get the text in the caption, which is saved as post_excerpt.

Of course you can show both the description and the caption!

-------------------------------------------------------------------
<?php
echo '<div class="re-featured-image">';
the_post_thumbnail();
echo '<div class="re-featured-image-description">' . get_post(get_post_thumbnail_id())->post_content . '</div>';
echo '<div class="re-featured-image-caption">' . get_post(get_post_thumbnail_id())->post_excerpt . '</div>';
echo '</div>';
?>
------------------------------------------------------------------
Development: 

Similar Content

Identify harmful Web Shell with PHP Shell Detector

webshell php

A web shell is a script, commonly written in PHP, which can provide access as the root user to a web server compressed. Trojan also renamed PHP can be very harmful if used correctly by an attacker, it is therefore important to periodically analyze the platform's web in search of intruders.
Development: 

How to spy a mobile phone

how to spy a mobile phone

Have you ever thought to spy your friend’s mobile phone or reading all messages on your girlfriend’s mobile and listen all her calls too.  Maybe you haven’t done it yet because you haven’t found a simply and cheaper way. So reading this guide you can finally try to do it.

There are a lot of free or very cheaper solutions even if you should use them only to make some joke and not to violate the privacy of other people. In this way, in fact, you will commit a serious crime!

Mobile: 

Facebook, 1 hour blackout in Europe

Last night, many users have reported on Twitter that Facebook was not accessible. A few minutes later Anonymous posted a message in which the group of hacktivists claimed the attack on the servers of the social network. A spokesman for Menlo Park has denied everything, saying that it was a simple technical problem.

News Magazine: 

Anonymous, this time hitting the State Police

The hacktivist group most famous against the most sensitive Italian goal. The hole suffered by the server of the State Police at the hands of Anonymous last night marks a quantum leap in the company's shares, which - perhaps because they have abandoned WikiLeaks - seem to be devoting more and more data leaks and dedicate to public shares.
News Magazine: 

On Google+ comes the zoom on photos

zoom google+Short, but interesting. It is the latest news on Google+, shared on the social network by Dave Cohen, Google.
 
It is zooming, used by the user when viewing photos. Everything is connected, quite simply, to the mouse wheel: moving it forward or backward, it becomes possible to zoom in or out details and particulars.
News Magazine: