【问题标题】:Using Shortcode inside string which includes html (WordPress PHP File)在包含 html(WordPress PHP 文件)的字符串中使用简码
【发布时间】:2021-05-14 07:42:53
【问题描述】:

我的 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() 函数解析。

我怎样才能把它放在那个 HTML 字符串中?

$content = '<div id="wrapper">' . do_shortcode('[image_hover target="_self" image="23162" link="/"]') . '<div>Lorem Ipsum</div></div>'

因为这种组合不起作用。

【问题讨论】:

    标签: php html wordpress shortcode wordpress-shortcode


    【解决方案1】:

    do_schortcode() 函数之前必须存储在一个变量中

    $shortcode = do_shortcode('[image_hover target="_self" image="23162" link="/"]');
    $content = '<div id="wrapper">' . $shortcode . '<div>Lorem Ipsum</div></div>';
    return $content;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-12
      • 1970-01-01
      • 2014-01-06
      • 2021-11-28
      • 2015-03-20
      相关资源
      最近更新 更多