I’d like to wrap my post thumbnail with <figure> tags.

I have tried the following and the image appears, but the <figure> tags come up empty.

<?php
if ( has_post_thumbnail() ) {
    echo '<figure>'.the_post_thumbnail('gallery').'</figure>';
}
?>

I’ve also tried the following, but the image is missing and only the empty <figure> tags appear.

<?php
if ( has_post_thumbnail() ) {
    echo '<figure>'.get_the_post_thumbnail('gallery').'</figure>';
}
?>

UPDATE

For anyone wanting the full code from the answer, here it is:

<?php
if ( has_post_thumbnail() ) {
    echo '<figure>'.get_the_post_thumbnail( $page->ID, 'gallery').'</figure>';
}
?>

2 Answers
2

Use get_the_post_thumbnail( $id, $size )
if you’re going to echo the result.

And make sure you have post thumbs enabled.

add_theme_support( 'post-thumbnails' );

Leave a Reply

Your email address will not be published. Required fields are marked *