PHPVariable=get_the_post_thump_url不带斜杠输出

时间:2021-03-04 作者:SRDMH

在一个自定义快捷码函数中,我获取了特色图像URL:

$text_slider_testimonial_img = get_the_post_thumbnail_url($single->ID);
如果我回音$text_slider_testimonial_img 我立即看到正确的图像URL://localhost:3000/wp-content/uploads/2021/03/splitbanner1.jpg

当我将此变量传递给函数时,该函数使用:

$text_slider_content .= "<div class=\'text_slider_testimonial\' style=\'background-size: cover; background-image: url(\'". $text_slider_testimonial_img ."\')>";
return $text_slider_content;    
上述样式组件输出为:

style="background-size: cover; background-image: url(" localhost:3000="" wp-content="" uploads="" 2021="" 03="" splitbanner1.jpg\')="">
为什么要删除斜杠="" 正在添加?

感谢您的帮助。

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

2 个回复
最合适的回答,由SO网友:Rahul bhut 整理而成

用下线替换该线可能会解决此问题。

$text_slider_content .= \'<div class="text_slider_testimonial" style="background-size: cover; background-image: url(\'. $text_slider_testimonial_img .\');">\';

SO网友:Abdul Awal Uzzal

用以下内容替换线路应能解决问题:

$text_slider_content .= "<div class=\'text_slider_testimonial\' style=\'background-size: cover; background-image: url($text_slider_testimonial_img);>";