A-A+

禁用wordpress评论的html代码

本文于2012年07月06日最后更新 博客心得

你是否遇到以下情况:

你是否有时候要帮网友不得不贴出自己的代码帮朋友们解决一些具体问题,但是wordpress的评论默认会将一些代码编译,这就无法让朋友看到代码,不管你遇没遇到,但张自然时遇到了,遇到就要着手解决,经过多方查找,终于让我找到了!!!所以我发出来,方便我以后查找,也给各位朋友提供便捷,方法如下:

在主题目录下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
$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);

效果演示请看我博客评论,你在我博客发html代码就不会被编译了!!!!!不用看张自然博客了,我又改回来了!!!

  1. 浪漫海岸
  2. 轻舞飞扬
  3. 小布跳跳

给张自然个人博客留言取消回复

Copyright © ZhangZiRan.com All Rights Reserved. 张自然个人博客 内容版权所有,同时保留所有权利。个人博客免责声明

用户登录