WordPress Email Obfuscation

Email obfuscation is a useful technique to use to stop spammers from finding your email address (as opposed to the more common “munging” where you write “me [at] blah [dot] com”). An obfuscated email address is unreadable to humans and most robots in the source code, but is rendered correctly in a browser, and will function correctly in a mailto link. I’ve found it works well…but it’s a pain in the arse to do by hand. There are free online tools that will obfuscate an email address for you, but what if you want an automatic solution.

I didn’t know this until WordPress Garage pointed it out, but it seems that WordPress has a built-in obfuscation function. It’s called antispambot().

The function antispambot() above parses the e-mail address passed by get_the_author_email() (this is the same as the_author_email(), except it returns rather than displays the author’s e-mail address). Use of the echo command displays the output of antispambot(). An interesting feature is it encodes only portions of an address, and does so randomly so the letters encoded are different each time the page loads, adding a little more firepower to the spam protection arsenal.

The wiki page on WordPress.org has an example on how to use the function.