【问题标题】:Allow HTML tags in wordpress shortcode content?在 wordpress 短代码内容中允许 HTML 标签?
【发布时间】:2014-03-23 02:41:56
【问题描述】:

我有一个简单的短代码,它接受一个属性和一些内容并返回一个 html 块:

function testimonial($atts, $content = null) {
extract(shortcode_atts(array(
    "by" => 'Joe'
), $atts));
return '<p class="testimonial">'.$content.'<br /><span>&mdash; '.$by.'</span></p>';
}
add_shortcode("testimonial", "testimonial");

并且海报可以包含一个短代码,例如:

[testimonial by="Bob Smith"]This was great![/testimonial]

我的问题是,如何让用户在其内容中插入简单的html标签,如&lt;b&gt;或&lt;br/&gt;,如:

[testimonial by="Bob Smith"]Excellent restaurant.<br/>Try the desserts![/testimonial]

由于该函数当前将“内容”作为字符串返回,因此代码显示。

【问题讨论】:

    标签: html wordpress wordpress-theming shortcode


    【解决方案1】:

    您可以允许自己解释短代码,例如,如果用户键入 [b],您可以在输出中将其替换为 &lt;strong&gt; 或 &lt;b&gt;。 IE。 $content可以

    str_replace("[b]","<strong>", $content);
    

    这只是这个想法的粗略示例。

    【讨论】:

      猜你喜欢
      • 2018-02-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多