T
T
towncitybr2021-08-23 12:42:44
css
towncitybr, 2021-08-23 12:42:44

How to display the post thumbnail in the background image of the block?

I try like this

<div class="contacts__image" style="background-image: url(<?php echo get_the_post_thumbnail_url( 'img/bg.jpg') ?>);"></div>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Litvinenko, 2021-08-23
@towncitybr

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

V
Vladik Bubin, 2021-08-23
@ikoit

You are outputting a whole img tag in styles. To get the image url, you need to use: get_the_post_thumbnail_url()
More details here: https://wp-kama.ru/function/get_the_post_thumbnail_url

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question