新闻中心

通过禁用主题评论中的html标记功能,防范wordpress垃圾评论

作者 / 无忧主机 时间 2012-03-30 12:39:46

wordpress的评论功能是非常强大,应用是非常丰富的,由于它支持html标记,正因为这个支持html标记,就很容易“招蜂引蝶”——垃圾评论。从而海量的垃圾评论无端的消耗我们空间宝贵的站点流量资源,而且由于支持html标记,什么超链接、加粗、斜体、表达等让我们的评论丰富多彩了,但同时也有可能给我带来一些不便。无忧主机(www.51php.com)认为wp默认评论支持html标记功能,是站长“痛并快乐着”的一个功能。 如果你想做出改变,你可以屏蔽这个功能,这样做,一来可以统一评论的风格,而来也可以拒绝一些垃圾评论,让一些刷垃圾评论的人失去兴趣(因为不支持超链接拉)。下面就详细说下这个操作方法: 打开wordpress主题模版,使用editplus编辑functions.php文件,在里面加入一段代码就可以解除评论的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; 保存后上传到wp主题目录就可以了。     纯Linux环境下高端免备案[香港独立IP地址] php空间,仅仅只需199元一年起。商务中国域名核心代理直销50元注册国际顶级域名

本文地址:https://www.51php.com/wordpress/5456.html

1
1
1
1
1
1
1

客户服务热线

0791-8623-3537

在线客服