adding an id to the_post_thumbnail

Use get_the_post_thumbnail() instead. It allows you to pass in an array of attributes for the image tag that gets returned.

For example:

$attr = array(
    'id' => 'YOUR-UNIQUE-ID',
);

echo get_the_post_thumbnail( $id, 'thumbnail', $attr );

EDIT:

I’m dumb. the_post_thumbnail() also lets you do that. Try passing the same args array I outlined as the second param.

Leave a Comment