WordPress评论中禁止HTML代码显示的方法

 
 

WordPress评论中禁止HTML代码显示的方法

文实例讲述了WordPress评论中禁止HTML代码显示的方法。分享给大家供大家参考。具体分析如下:
使用WordPress的朋友会发现如果我们开户了博客评论会经常看到大量的垃圾广告,带连接了,那么我们要如何禁止用户输入html标签原样输出,而不显示呢,下面我来给大家介绍.
html标题无非就是由“<”、“>”组成了,我们可以反它转换成“&lt;”、“&gt;”,这样通过HTML编译,自动变成了“<”、“>” 我们也可以直接替换掉了
找到一国外人的代码,搞定了,不过不一定他是原作者,在主题的 functions.php的PHP代码里加入如下代码:
//禁用wordpress评论html代码
// This will occur when the comment is posted
function plc_comment_post( $incoming_comment ) {
// convert everything in a comment to display literally
$incoming_comment['comment_content'] = htmlspecialchars($incoming_comment['comment_content']);
// the one exception is single quotes, which cannot be #039; because WordPress marks it as spam
$incoming_comment['comment_content'] = str_replace( "'", ''', $incoming_comment['comment_content'] );
return( $incoming_comment );
}
// This will occur before a comment is displayed
function plc_comment_display( $comment_to_display ) {
// Put the single quotes back in
$comment_to_display = str_replace( ''', "'", $comment_to_display );
return $comment_to_display;
}
add_filter( 'preprocess_comment', 'plc_comment_post', '', 1);
add_filter( 'comment_text', 'plc_comment_display', '', 1);
add_filter( 'comment_text_rss', 'plc_comment_display', '', 1);
add_filter( 'comment_excerpt', 'plc_comment_display', '', 1);

 

540 Views
分享你的喜爱
linwute
linwute

我要像梦一样自由,像大地一样宽容;
在艰辛放逐的路上,点亮生命的光芒;
我要像梦一样自由,像天空一样坚强;
在曲折蜿蜒的路上,体验生命的意义;

留下评论

您的电子邮箱地址不会被公开。 必填项已用 * 标注