Вопрос

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.

Here is the wider code context (pastebin.com).

Это было полезно?

Решение

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 .');">';

Другие советы

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);>";
Лицензировано под: CC-BY-SA с атрибуция
Не связан с wordpress.stackexchange
scroll top