Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

How to display the caption from the_post_thumbnail? WordPress



I have the_post_thumbnail(); in my template and want to display the caption, alt text, title and description for the associated image. How do I retrieve and echo these values?

Thanks in advance,

Answers (3)


S├ębastien | French WordpressDesigner answers:

add this
if(has_post_thumbnail()) {

$thumb_id = get_post_thumbnail_id();
$args = array(
'ID' => $thumb_id,
'post_type' => 'attachment',
'post_parent' => $post->ID,
'numberposts' => 1


$attachments = get_posts($args);

if ($attachments) {
foreach ($attachments as $attachment) {
the_attachment_link($attachment->ID, false);//display the image
echo apply_filters('the_title', $attachment->post_excerpt);//display the caption

after while (have_posts()) : the_post();


Rashad Aliyev answers:

Please read here: [[LINK href=""]][[/LINK]]

Cartogram comments:

My apologies, I will be more specific. I am looking to display the featured image and then display the caption for that featured image below it.

I do not think the link to the wordpress codex explains how to do that. Thanks anyways.



hemant hapani answers:


Pls try this code...

$thumb_id = get_post_thumbnail_id($post->id);
$args = array(
'p' => $thumb_id,
'post_type' => 'attachment'
$thumb_image = get_posts($args);
$thumb_caption = $thumb_image->post_excerpt;

Cartogram comments:

I could not get this to work, how would I implement it into the following template...

get_header(); ?>

<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>

<div class="wrap-inner" id="post-<?php the_ID(); ?>">
<?php echo get_the_post_thumbnail($page->ID, 'full'); ?>

<div id="page-content" class="wrap">
<div class="wrap-inner">
<?php the_content(); ?>
<?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyten' ), 'after' => '</div>' ) ); ?>
<?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="edit-link">', '</span>' ); ?>
</div><!-- .entry-content -->
</div><!-- #post-## -->

<?php endwhile; ?>
<?php get_footer(); ?>