有些项目和用户会利用软件对网络上的邮件地址进行收集,然后有针对的群发邮件。如果我们网站采用的是WordPress程序,我们可以采用Antispambot插件自动将网站中邮件Email地址进行加密,在源代码中是看不到邮箱信息的。我们也可以通过无代码实现。


function security_remove_emails($content) {<br> $pattern = '/([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,4})/i';
$fix = preg_replace_callback($pattern,"security_remove_emails_logic", $content);
return $fix;<br> }<br> function security_remove_emails_logic($result) {
return antispambot($result[1]);
}
add_filter( 'the_content', 'security_remove_emails', 20 );
add_filter( 'widget_text', 'security_remove_emails', 20 );

我们在当前主题的functions.php文件中加上代码,同样可以实现用插件的效果。


扫描二维码,在手机上阅读!