百度
360搜索
搜狗搜索

WordPress评论中禁止HTML代码显示的方法详细介绍

这篇文章主要为大家介绍了WordPress评论中禁止HTML代码显示的方法,通过增加自定义函数有效防止垃圾评论的产生,是非常实用的技巧,需要的朋友可以参考下

本文实例讲述了中禁止代码显示的方法。分享给大家供大家参考。具体分析如下:

使用WordPress的朋友会发现如果我们开户了博客评论会经常看到大量的垃圾广告,带连接了,那么我们要如何禁止用户输入html标签原样输出,而不显示呢,下面我来给大家介绍.

html标题无非就是由“<”、“>”组成了,我们可以反它转换成“&lt;”、“&gt;”,这样通过HTML编译,自动变成了“<”、“>” 我们也可以直接替换掉了

找到一国外人的代码,搞定了,不过不一定他是原作者,在functions.的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

$inc
oming_comment['comment_content'] = htmlspecialchars($incoming_c omment['comment_content']);

// the o http://ne exception is single quotes, which cannot be #039; because WordPress marks it as spam

$incoming_comment[
'comment_content'] = str_replace( "'", '&apos;', $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( '&apos;', "'", $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_', 'plc_comment_display', '', 1);

add_filter( 'comment_excerpt', 'plc_comment_display', '', 1);

希望本文所述对大家的WordPress建站有所帮助。

本文标题: WordPress评论中禁止HTML代码显示的方法 ,

网站数据信息

"WordPress评论中禁止HTML代码显示的方法"浏览人数已经达到46次,如你需要查询该站的相关权重信息,可以点击进入"Chinaz数据" 查询。更多网站价值评估因素如:WordPress评论中禁止HTML代码显示的方法的访问速度、搜索引擎收录以及索引量、用户体验等。 要评估一个站的价值,最主要还是需要根据您自身的需求,如网站IP、PV、跳出率等!