Automatically Hide Email Addresses From Spambots

Spambots are one of the most annoying things you have to deal with when running a website or blog. They scan your site for email addresses just so it can be used for sending out spam. Well, thanks to a certain Stian Jacobsen, he was nice enough to share this nifty snippet to help you combat those annoying programs.

ScreenHunter 990 Nov. 26 08.52 Automatically Hide Email Addresses From Spambotsfunction 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', 'security_remove_emails', 20 );

add_filter( 'widget_text', 'security_remove_emails', 20 );

This code helps prevent spambots from detecting any email addresses that you may have in your site simply by hiding them. All you have to do is to insert the code into your functions.php file and that’s it. Once the file’s saved, the code filter content and widget content to hide all emails from the nasty critters.

Incoming search terms for the article:

Related Posts

Create A Responsive Retina-Ready Menu

How to Create a Geometric Shaped Typography with Grungy Background

Optimize Your Site For Retina Display

How to Create a Clean and Colorful Web Layout