Set Wordpress Thumbnail as background

Asked

Viewed 209 times

0

I need to put the Wordpress thumbnail as background in a div

Currently has img even, using Loop::thumbnail()

1 answer

0


You can insert the url of the thumbail into a style inside the div, this way every time you change the thumbnail it will be changed in the background of the div too:

<div style="background-image: url("<?php echo get_the_post_thumbnail_url(get_the_ID()) ?>");">
</div>

Remember to pass the post id as a function parameter get_the_post_thumbnail_url().

  • It worked out! I had done something similar here too. Thanks!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.