默认情况下,WordPress允许在评论中包含某些HTML标记,例如<;a>;<;em>;<;<;strong>;等。如果您注意到许多垃圾评论也包含这些标记。大多数垃圾评论都是由机器人和脚本发出的,它们使用的是HTML标签。如果你简单地从你的WordPress评论中禁用了HTML,它就可以防止大量的垃圾邮件。在本教程中,我们将向您展示如何在您的WordPress评论中禁用HTML标签。
本教程将仅禁用活动的HTML标记。因此,有人仍然可以发布类似以下内容的内容:
&;lt;a&;gt;&;lt;em&;gt;&;lt;strong&;gt;
它会显示出来,但标签将不起作用。因此,如果有人使用强标记,则不会将文本加粗。此外,没有多少垃圾邮件机器人有时间这样做,因为这种方式占用了大量的时间,这对他们没有好处。
你所要做的只是打开你的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;
}
由❤️托管WPCode
在WordPress中一键使用
如果你不想自己手动添加这段代码,那么原创作者也提供了一个插件,你可以下载。只需安装并激活Peter的文字评论插件。
这种方法更好的原因是它不需要您更改核心文件。如果你想编辑你的核心文件,你可以去Wp-includes/kse.php然后在那里编辑代码。(不建议这样做,但这里是为了了解情况。(更多细节请参阅WP Codex)

