Skip to content
Advertisement

WordPress how to get the post thumbnail inside a figure tag

I am running a query loop and want that ‘if‘ the post has a featured image, it needs to be inside a <figure> tag. But the featured image’s <img> tag is appearing before the <figure> tag. What could be the reason?

JavaScript

The problem can be better understood with this image: enter image description here

Advertisement

Answer

It’s because you’re using the_post_thumbnail function which echo the image by default which happens sooner than echoing out the figure tag.

Replace

JavaScript

with

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement