October 24, 2018
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); }