WPLOGO

禁用 wordpress评论内的HTML

评论存在HTML会被发大量的广告,甚至恶性代码,如果处理不即时可能会出现问题,当然如果设置全部评论都需要审核当然没有问题,但你的网站访问量到一定规模,就会显得麻烦。

还有一个讨厌的地方,就是评论下面的那些HTML代码提示,要删除正常情况下要修改WORDPRESS核心文件comment-template.php,在wp-includes文件夹内,缺点是如果WORDPRESS进行更新,有可能就要重新修改,禁用更新还会面临漏洞无法修复的风险。所以就要在咱们模板里进行设置屏蔽掉这段显示。

屏蔽这段显示很简单,只需要打开模板文件夹内的comment.php文件,搜索代码


替换成为

 '')); ?>

禁用HTML方法也很简单,将下面这段代码加进模板文件夹内的functions.php文件空白处

function uazoh_comment_post( $incoming_comment ) {
	$incoming_comment['comment_content'] = htmlspecialchars($incoming_comment['comment_content']);
	$incoming_comment['comment_content'] = str_replace( "'", ''', $incoming_comment['comment_content'] );
	return( $incoming_comment );
}

function uazoh_comment_display( $comment_to_display ) {
	$comment_to_display = str_replace( ''', "'", $comment_to_display );
	return $comment_to_display;
}

add_filter('preprocess_comment', 'uazoh_comment_post', '', 1);
add_filter('comment_text', 'uazoh_comment_display', '', 1);
add_filter('comment_text_rss', 'uazoh_comment_display', '', 1);
add_filter('comment_excerpt', 'uazoh_comment_display', '', 1);

发布者

优佐

Uazoh优佐生活