iphone-email

Obfuscating email addresses in WordPress

| 1 Comment

Sad though it may be, it can be dangerous to publish your email address online because your privacy is then destroyed (and you’ll be receiving a lot of junk mail moving forward).

The typical way of getting around this is by providing a contact form, where the email address is hidden from the end user. However, there are times when it would be useful to display the email address without the risk of spiders and email harvesting software from picking it up.

WordPress has a built-in function for doing just that, called antispambot().. You can pass any email address to this function and it returns the same email address, but encoded in HTML entities. This makes it harder for harvesting software to recognise it as an email address, but still displays completely normally to the end user.

Since it’s a WordPress function, you can either build it into your theme files, or you can create a shortcode to wrap email addresses to use it within posts, pages and widgets. To do that, drop the following snippet into your functionality plugin:

By way of example, using me@mysite.com inside that shortcode looks normal on the front end, but when you look at the page source (which Google and crawlers etc. read), you’ll see that it’s far from recognisable as an email address:

This is a great way to make your email address public, without making it public, if you know what I mean.

Categories: Code & Snippets, Security | Permalink

What next?

Hire me

If you couldn't quite manage this yourself, find it too intimidating, or just don't have the time to do it, you can always hire Dave to do it. Please get in touch so that we can discuss your needs.

Leave a comment

If you have a question, update, or comment about the tutorial, please leave a comment. I try and respond to every comment, though it may take a few days, so please check back soon.

Let a WordPress Expert help you

Do you want to try this, but feel like you need a helping hand, in case something goes wrong? My service, The WP Butler, gives you access to WordPress expertise whenever you need it. Better yet, I'll keep your site backed up, updated and secure, so that you don't have to worry about it. It's all part of the service. Use coupon DIWW and save 15% on all plans.

Visit The WP Butler

Author:

Dave has been tinkering with WordPress for many years, and he now shares his WordPress knowledge here on Do It WIth WordPress to help others realise its impressive power. He can also be hired to help with your WordPress needs. Dave, who is British, is married to his best friend, Marti, with whom he has a beautiful daughter, Ellie. When he's not dabbling with WordPress, he's probably eating Triscuits or hummus, watching an indie film or British TV show, spending time with friends or family, or exploring the world.

One Comment

  1. Hi Dave,
    some years ago I wrote a shortcode function for my “functionality” plugin and it’s available here: https://gist.github.com/aldolat/6e234d0baf479f5c6775

    It contains some extra options that could be useful to someone. Also, it lets us define a custom text linked to an email address.

    Cheers!

Leave a Reply