有时候访客的评论中含有不雅的词汇,这让你的博客看上去不那么美,或者有些词比较敏感,最好给过滤掉,或者你想让有些词特定显示成你喜欢的字词,让博客比较有趣。这时你就可以使用下面这段代码加在functions.php,让你在评论中替换一些关键词。
add_filter( 'pre_comment_content', 'wpFilterComment' );
function wpFilterComment($comment) {
$replace = array(
// 'WORD TO REPLACE' => 'REPLACE WORD WITH THIS'
'foobar' => '*****',
'hate' => 'love'
);
$comment = str_replace(array_keys($replace), $replace, $comment);
return $comment;
}