一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

WordPress博客评论禁止HTML代码显示

时间:2013-06-15 编辑:简简单单 来源:一聚教程网

html标题无非就是由“<”、“>”组成了,我们可以反它转换成“<”、“>”,这样通过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);

热门栏目