Site logo

Archived topic

Can't get the correct position for the Featured Image's caption

3 replies · Started by tbgr on February 17, 2020

Viewing posts 1–4 of 4

I've tried the various suggestions here for adding a caption to the Featured Image.

I DID get it to work, but the caption is not UNDER the photo, as shown here:

https://i.postimg.cc/Twr7MTtN/blair-caption.png

Is there a way to have the caption directly under the photo?

Thank you.

Hi there,

Can you try this code instead:

add_action( 'generate_before_content', 'db_featured_image_caption', 15 );
function db_featured_image_caption() {
    $get_description = get_post(get_post_thumbnail_id())->post_excerpt;
    if(!empty($get_description) && is_single() ){    
        echo '<div class="featured_caption">' . $get_description . '</div>';
    }
}

Then this CSS:

.featured_caption {
    text-align: center;
}

Adding CSS: https://docs.generatepress.com/article/adding-css/

If this doesn't work, we'd need to see the live site.

Let me know :)

Thanks, Leo.

That did the trick!

No problem :)

This archived topic is closed to new replies.