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:
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
