在wordpress短代码内容中允许使用HTML标签吗?

时间:2014-02-21 14:16:33

标签: html wordpress wordpress-theming shortcode

我有一个简单的短代码,它接受一个属性和一些内容并返回一个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标记,例如<b><br/>,例如:

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

由于函数当前以字符串形式返回“content”,因此代码显示。

1 个答案:

答案 0 :(得分:0)

您可以允许自己对短代码的解释,例如,如果用户输入[b],您可以在输出中将其替换为<strong><b>。即$content可以是

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

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

相关问题