Function to Obfuscate Emails

Spam and malware bots are being programmed smarter, and they can sometimes target email urls that are placed in the content area.To prevent your emails from being bogged down by unwanted spam messages, place the following function in your WordPress Theme’s function.php file.

This will target all of the embedded email urls and alter them automatically so they cannot be sourced by bots. It will save you the time of having to go through all of your content and update the emails manually!

function getObfuscatedEmailAddress($email) {
   // check for emails
   return str_replace(array(".","@"), array("[dot]","[at]"), $email);
}

function filter_the_content_change_emails( $content ) {
   // Check if we're inside the main loop in a single post page.
   return str_replace(array("@katherinegoodmanson.ca"), array("[at]katherinegoodamnson[dot]ca", $content);
}

add_filter( 'the_content', 'filter_the_content_change_emails' );

Alternatively:

function getObfuscatedEmailAddress($email) {
   // check for emails
   return str_replace(array(".","@"), array("@","."), $email);
}

Leave a Reply

Posted in php
katherine as a flat graphic icon

About Me

I’m an African / Ojibwe First Nations Web Developer living in Winnipeg, Manitoba.

Visit the Tips and Blog to see what I’m working on.