PHP variable = get_the_post_thumbnail_url outputting without slashes
-
19-05-2021 - |
Pregunta
In a custom shortcode function, I'm grabbing the featured image URL:
$text_slider_testimonial_img = get_the_post_thumbnail_url($single->ID);
If I echo $text_slider_testimonial_img
immediately I see the correct image URL: //localhost:3000/wp-content/uploads/2021/03/splitbanner1.jpg
When I pass this variable to a function, and that function uses:
$text_slider_content .= "<div class='text_slider_testimonial' style='background-size: cover; background-image: url('". $text_slider_testimonial_img ."')>";
return $text_slider_content;
the style component of the above is output as:
style="background-size: cover; background-image: url(" localhost:3000="" wp-content="" uploads="" 2021="" 03="" splitbanner1.jpg')="">
Why are the slashes being stripped out, and the =""
being added?
Help appreciated.
Solución
Replacing the line with below line may solve the issue.
$text_slider_content .= '<div class="text_slider_testimonial" style="background-size: cover; background-image: url('. $text_slider_testimonial_img .');">';
Otros consejos
Replacing the line with following should solve the issue:
$text_slider_content .= "<div class='text_slider_testimonial' style='background-size: cover; background-image: url($text_slider_testimonial_img);>";
Licenciado bajo: CC-BY-SA con atribución
No afiliado a wordpress.stackexchange