[英]Using Shortcode inside string which includes html (WordPress PHP File)
我的 php 文件中有一个变量,其中包括 HTML,如下所示:
$content = '<div id="wrapper"><div>Lorem Ipsum</div></div>'
return $content;
在 HTML 中返回:
<div id="wrapper">
<div>Lorem Ipsum</div>
</div>
但我想在这里添加一些东西:
<div id="wrapper">
{HERE} <-----
<div>Lorem Ipsum</div>
</div>
我要添加的不是 HTML 因为它的 WordPress 短代码是这样的:
[image_hover target="_self" image="23162" link="/"]
可以使用 PHP echo 或 WordPress 中的do_schortcode() function 解析。
我怎样才能把它放在 HTML 字符串中?
$content = '<div id="wrapper">' . do_shortcode('[image_hover target="_self" image="23162" link="/"]') . '<div>Lorem Ipsum</div></div>'
因为这种组合不起作用。
do_schortcode() function 必须先存储在变量中
$shortcode = do_shortcode('[image_hover target="_self" image="23162" link="/"]');
$content = '<div id="wrapper">' . $shortcode . '<div>Lorem Ipsum</div></div>';
return $content;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.