默认情况下,WordPress允许在评论中包含某些HTML标签,例如等。如果您发现很多垃圾评论也包含这些标签。大多数垃圾邮件评论是由使用HTML标签的机器人和脚本发出的。如果您只是在WordPress评论中禁用HTML,就可以防止大量垃圾邮件。在本教程中,我们将向您展示如何禁用WordPress评论中的HTML标签。
本教程将仅禁用活动HTML标签。所以有人仍然可以发布类似的内容:
它会显示,但标签不起作用。因此,如果有人使用强标记,它不会将文本加粗。此外,没有多少垃圾邮件机器人有时间这样做,因为这种方式占用大量时间,并且对他们没有好处。
立即学习“前端免费学习笔记(深入)”;
您所要做的就是打开您的functions.php并添加以下代码:
//Thiswilloccurwhenthecommentispostedfunctionplc_comment_post($incoming_comment){//converteverythinginacommenttodisplayliterally$incoming_comment['comment_content']=htmlspecialchars($incoming_comment['comment_content']);//theoneexceptionissinglequotes,whichcannotbe#039;becauseWordPressmarksitasspam$incoming_comment['comment_content']=str_replace("'",''',$incoming_comment['comment_content']);return($incoming_comment);}//Thiswilloccurbeforeacommentisdisplayedfunctionplc_comment_display($comment_to_display){//Putthesinglequotesbackin$comment_to_display=str_replace(''',"'",$comment_to_display);return$comment_to_display;}