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

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

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

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?


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');
  • thanks very much. Guess I cant reuse the $product_pic. This worked. – Manny Apr 25 at 20:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.