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

   2015-08-02 0
核心提示:这篇文章主要为大家介绍了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( "'", '&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_rss', 'plc_comment_display', '', 1);
add_filter( 'comment_excerpt', 'plc_comment_display', '', 1);

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

 
标签: WordPress 评论 方法
反对 0举报 0 评论 0
 

免责声明:本文仅代表作者个人观点,与乐学笔记(本网)无关。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
    本网站有部分内容均转载自其它媒体,转载目的在于传递更多信息,并不代表本网赞同其观点和对其真实性负责,若因作品内容、知识产权、版权和其他问题,请及时提供相关证明等材料并与我们留言联系,本网站将在规定时间内给予删除等相关处理.

点击排行