getting url from variable that calls picture of current page, not working. Only displays everything instead of url

I am trying to echo an image to the background like so

$product_pic = get_the_post_thumbnail($pid, 'full');
$pid = $result[0]->productID;

<style>
    .product-pic-bg{background-image:url("<?php echo  $product_pic;?>")}
</style>

It doesn’t work. All I get is .product-pic-bg{url""} in the console.

When I dump the $product-pic I get:

getting url from variable that calls picture of current page, not working. Only displays everything instead of url

What do I do to get this to work?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

get_the_post_thumbnail function returns the post thumbnail image tag as a string.
Use get_the_post_thumbnail_url function instead to get url.

$url = get_the_post_thumbnail_url($pid, 'full');


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x