Block the robot from searching your website for the email address for the php code

  • 2020-05-26 08:06:44
  • OfStack

Spam is annoying, so here's a way to automatically block bots from collecting email addresses from your website.
 
function security_remove_emails($content) { 
$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; 
} 
function security_remove_emails_logic($result) { 
return antispambot($result[1]); 
} 
add_filter( 'the_content', 'flex_remove_emails', 20 ); 
add_filter( 'widget_text', 'flex_remove_emails', 20 ); 

Put this in the functions.php file, and if the robot collects the email address, it will automatically block it.

Related articles: