在包含 html 的字符串中使用简码(WordPress PHP 文件)
Using Shortcode inside string which includes html (WordPress PHP File)
我的 php 文件中有一个变量,其中包括 HTML,如下所示:
$content = '<div id="wrapper"><div>Lorem Ipsum</div></div>'
return $content;
HTML 中的 returns:
<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() 函数解析。
我怎样才能把它放在 HTML 字符串中?
$content = '<div id="wrapper">' . do_shortcode('[image_hover target="_self" image="23162" link="/"]') . '<div>Lorem Ipsum</div></div>'
因为这个组合不起作用。
do_schortcode() 函数之前必须存储在一个变量中
$shortcode = do_shortcode('[image_hover target="_self" image="23162" link="/"]');
$content = '<div id="wrapper">' . $shortcode . '<div>Lorem Ipsum</div></div>';
return $content;
我的 php 文件中有一个变量,其中包括 HTML,如下所示:
$content = '<div id="wrapper"><div>Lorem Ipsum</div></div>'
return $content;
HTML 中的 returns:
<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() 函数解析。
我怎样才能把它放在 HTML 字符串中?
$content = '<div id="wrapper">' . do_shortcode('[image_hover target="_self" image="23162" link="/"]') . '<div>Lorem Ipsum</div></div>'
因为这个组合不起作用。
do_schortcode() 函数之前必须存储在一个变量中
$shortcode = do_shortcode('[image_hover target="_self" image="23162" link="/"]');
$content = '<div id="wrapper">' . $shortcode . '<div>Lorem Ipsum</div></div>';
return $content;