Is there a Wordpress PHP code to call an image Caption, Alternative Text, and Decription? I have several images with Titles, captions, alt text and Description fields filled and would like to display these on the image.

I know how to call the image title:

<h1><?php the_title(); ?></h1>

How to do so with the other fields?

Here's a sample of the rest of my code (this is for a slideshow)

<div class="slide">

    <?php if ( get_post_meta( $post->ID, "slide_url_value", $single = true ) != "" ): ?>
    href="<?php echo get_post_meta( $post->ID, " slide_url_value ", $single = true ); ?>"
    title="<?php the_title(); ?>">
        <?php the_post_thumbnail( 'featured-slide', array( 'title' => get_the_title() ) ); ?>

    <?php else: ?>
    <?php the_post_thumbnail( 'featured-slide', array( 'title'=>get_the_title() ) ); ?>
    <?php endif; ?>
        <h1><?php the_title(); ?></h1>


Is there a way to use <?php the_field(''); ?> or id slugs?

  • 1
    You could try using get_attachment_metadata() - View Codex
    – Howdy_McGee
    Commented Mar 27, 2014 at 23:37

1 Answer 1


WordPress stores image (attachment) data as follows:

  • Description: post_content field
  • Caption: post_excerpt field
  • Alt: _wp_attachment_image_alt meta value

And in code, that translates to:

// Description
echo $post->post_content; // Raw

// Caption (description as fallback)

// Caption (explicitly)
echo $post->post_excerpt; // Raw
if ( has_excerpt() ) {

// Alt
echo get_post_meta( $post->ID, '_wp_attachment_image_alt', true );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.