Preventing email spam with the built-in WordPress email obfuscator

July 10, 2008 – 8:57 am | by Miriam Schwab

If you want to give people the option to contact you by email, you need to display your email address on your site. But by doing so, you are putting yourself at the mercy of the low-lives out there harvesting email addresses so they can spam you with products that will enlarge certain parts of your body.

There are solutions out there that use javascript and other stuff to “obfuscate” your email address, but why use something external when you can use the handy, shiny, built-in WordPress email obfuscating template tag?

To use this template tag, you need to do the following:

  1. Make sure your email address is in your user profile.
  2. Put the following template tag wherever you want the address to appear:
    <?php echo antispambot(get_the_author_email()); ?>

The WordPress codex says that this tag works as follows:

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.

My questions are:

  1. Since this pulls an author related parameter, will the email address change according to the author? (Probably.)
  2. Can this even be displayed in the sidebar?

It seems that if it is author related, it is not a good solution for displaying a website email address that does not belong to a specific person, like . But if you do have a multi-author site and you want to display the authors’ email addresses, this seems like a great way to do that without feeding the spam wolves.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]
  1. 8 Responses to “Preventing email spam with the built-in WordPress email obfuscator”

  2. By tekkie on Sep 15, 2008 | Reply

    Mac OS X users can also manually use a Dashboard widget called obfuscatr. It provides JS or just plain encoding of your email. See the details article at flash tekkie. obfuscatr was also featured in MacWorld Italy of March 2008.

  3. By csleh on Jul 15, 2009 | Reply

    unfortunately the tag doesn’t show anything in wp 2.8.1. Use an obfuscator to hide, but a contact form is a better idea.

  4. By Jeremy Carlson on Dec 3, 2009 | Reply

    @csleh: WP 2.8.4 seems to work just fine with the `antispambot` tag. I was using `get_the_author_meta(‘user_email’)` for grabbing the address. You might try that…
    Contact forms are nice, but a lot of people want to be able to click on a link to email (in part for their own concerns about privacy), and this is pretty much the best solution for that situation.
    To grab an author’s email outside of the loop, you need to specify which author, like so:
    `get_the_author_meta(‘user_email’,2)`
    …where ‘2′ is the author’s ID.

  5. By ND on Dec 20, 2009 | Reply

    I used to have Private daddy on my web site. Now there’s also a WordPress plug-in for the rest of us. It does this automatically: http://www.privatedaddy.com/wordpress

  6. By Miriam Schwab on Dec 20, 2009 | Reply

    @ND thanks for telling us about Private Daddy! I’m going to check that out. Seems like an interesting service.

  1. 3 Trackback(s)

  2. Jul 15, 2008: WordPress Email Obfuscation | Webmaster-Source
  3. Jul 16, 2008: Bitwire.TV | WordCast 21: Purple Knuckles
  4. Sep 26, 2008: WordCast » Blog Archive » WordCast 21: Purple Knuckles

Post a Comment

Studio Press Premium Themes