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

Guide step by step: How to use Youtube Annotations

how to use youtube annotationsYouTube annotations are among the most valuable tools that YouTube offers us to increase the members of the channel, make more involving videos, add information, create interactive stories and link to other videos, channels, profiles, Google Plus or YouTube search results.

Social Network: 

How to download .flv videos from Google, YouTube, MySpace and convert to Avi / Dvx without Software

how to download flv videosMany of you are aware that there are many sites that offer the ability to watch videos on-line of all kinds, but downloading is not as simple, or rather you have to have a little 'familiarity with various open source tools like Firefox and its extensions.

Offline Utility: 

How to download free app from the Windows 8 store: wscrack_64/32 download

win 98The latest Microsoft operating system, Windows 8, is distinguished from its predecessors by adding a feature, the store, which offers free and paid apps, but this store is really so invulnerable to hackers? It seems not and today we give you a way to download all the free app ....

Offline Utility: 

How to create a Recovery Disk in Windows 8, to repair damaged installation

 

win 8 repair diskFor Windows 8 operating systems, it is very important to create a recovery disk to then use it in case of problems when you start your computer, or even just to carry out a reset to factory settings.
 
Here's how to create your own unique rescue disk.
Offline Utility: