怎么禁用 WordPress 评论里的HTML标记

WordPress教程 6724

相信大部分WP博主都知道,WordPress 默认的评论可以包括各种HTML标记语言,如超链接、加粗加斜、表单等等,这是一个不错的支持功能,但又是一个很坏的支持功能,因为这个功能在评论友好的同时也把垃圾评论留言招引来了,受过垃圾评论迫害的博主都知道垃圾留言的麻烦。所以有时候禁用 wordpress 评论里的HTML标记是非常有必要的。

禁用 wordpress 评论的HTML标记:

在博客当前使用的主题模板中的functions.php文件(如果没有就自己创建一个)中的<?php和?>之间添加以下代码:

// 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( "'", '&amp;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( '&amp;apos;', "'", $comment_to_display );
return $comment_to_display;

保存文件后,WP评论里的HTML标记就会失效。

精品推荐: