WordPress后台全英文的垃圾评论如何屏蔽?本着能不用插件就不用插件的原则,在主题的functions.php插入代码即可屏蔽全英文垃圾评论,新手站长分享WP垃圾评论拦截和过滤的方法:

WordPress全英文垃圾评论必须含中文评论
WordPress全英文垃圾评论拦截方法
WordPress后台经常会有全英文垃圾评论,需要屏蔽拦截一下,不然有一天打开你的WordPress后台,你会发现成千上万的垃圾评论,让你删除到窒息。只需要在WordPress主题目录下的functions.php中粘贴以下代码即可:
functions.php文件路径为/wp-content/themes/你的主题/functions.php
/* refused spam */
function refused_spam_comments( $comment_data ) {
$pattern = '/[一-龥]/u';
if(!preg_match($pattern,$comment_data['comment_content'])) {
wp_die('评论必须含中文!');
}
return( $comment_data );
}
add_filter('preprocess_comment','refused_spam_comments');
将上述代码复制粘贴到functions.php文件中即可。可以做下测试,当输入全字母的评论后,会提示“评论必须含中文!”。
阿里云官方活动:https://t.aliyun.com/U/FzmsXA
腾讯云官方活动:https://curl.qcloud.com/oRMoSucP
