是否允许在wordpress短代码内容中使用HTML标记?
我有一个简单的短代码,它接受一个属性和一些内容,并返回一个html块:是否允许在wordpress短代码内容中使用HTML标记?,html,wordpress,wordpress-theming,shortcode,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>— '.$by.'</span>
function testimonial($atts, $content = null) {
extract(shortcode_atts(array(
"by" => 'Joe'
), $atts));
return '<p class="testimonial">'.$content.'<br /><span>— '.$by.'</span></p>';
}
add_shortcode("testimonial", "testimonial");
我的问题是,如何允许用户在其内容中插入简单的html标记,例如
或
,例如:
[testimonial by="Bob Smith"]Excellent restaurant.<br/>Try the desserts![/testimonial]
[推荐人=“鲍勃·史密斯”]这家餐厅很棒。
尝尝甜点吧![/证明]
由于函数当前以字符串形式返回“内容”,因此代码将显示。您可以允许自己解释短代码,例如,如果用户键入
[b]
,您可以在输出中将其替换为
或
。也就是说,$content
可以
str_replace("[b]","<strong>", $content);
stru替换(“[b]”,“”,$content);
这只是一个粗略的例子
str_replace("[b]","<strong>", $content);