如何在WordPress注释中禁用HTML

默认情况下,WordPress允许注释中包含某些HTML标记,例如 a 、 e 、strong等。如果您注意到许多垃圾邮件注释也包含这些标记。大多数垃圾邮件评论是由使用HTML标记的机器人和脚本发出的。如果你只是在WordPress评论中禁用HTML,它可以防止大量的垃圾邮件。在本教程中,我们将向您展示如何禁用WordPress评论中的HTML标记。

本教程将仅禁用活动的HTML标签。因此,某人仍然可以发布类似的内容:
& lt; a> & lt; em> & lt; strong>

它会显示出来,但是标签不会起作用。所以如果有人使用strong标记,它不会加粗文本。此外,没有多少垃圾邮件机器人有时间这样做,因为这种方式占用了大量的时间,这对他们没有好处。

您只需打开functions.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( "'", ''', $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;
}

如果您不想自己手动添加这段代码,那么原作者还提供了一个可以下载的插件。只需安装并激活Peter的文字评论插件。

这种方法之所以更好,是因为它不需要更改核心文件。如果你想编辑你的核心文件,你可以去wp-includes/kses.php编辑代码。

chuangye

chuangye

chuangye

 

chuangye

Joomla的老巢