Question

I'm displaying a featured image (as a background) in a hero div, and using the caption to add some content from the Media Library automatically. I'd also like to use the image's description field and title, but can't find documentation on that. Here's what I have so far, which works as expected:


<div class="hero">
    <?php $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full' );?>
    <div class="hero-image" style="background-image: url('<?php echo $thumb['0'];?>')"></div>
    <div class="hero-content">
        <h1>NEED IMAGE DESCRIPTION HERE</h1>
        <p class="caption"><?php get_the_post_thumbnail_caption(); ?><?php the_post_thumbnail_caption(); ?></p>
    </div>
</div>

I'm not sure if I'm already getting that info, but not echoing it...or if I need to do more to get it from the database. Thanks in advance for your help!

Was it helpful?

Solution

this might work:

$post_thumbnail_id = get_post_thumbnail_id($post->ID); $thumbnail_image = get_posts(array('p' => $post_thumbnail_id, 'post_type' => 'attachment')); if ($thumbnail_image && isset($thumbnail_image[0])) { $img_description = $thumbnail_image[0]->post_content; $img_caption = $thumbnail_image[0]->post_excerpt; $img_alt = get_post_meta($post_thumbnail_id , '_wp_attachment_image_alt', true); $img_title = $thumbnail_image[0]->post_title; }

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top