PHP code to call image Caption, Alternative Text, and Decription?

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:

Read More
<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 ) != "" ): ?>
    <a 
    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() ) ); ?>
    </a>

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

</div>

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

Related posts

Leave a Reply

1 comment

  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
    the_content();
    
    // Caption (description as fallback)
    the_excerpt();
    
    // Caption (explicitly)
    echo $post->post_excerpt; // Raw
    if ( has_excerpt() ) {
        the_excerpt();
    }
    
    // Alt
    echo get_post_meta( $post->ID, '_wp_attachment_image_alt', true );