As owner of a website, it’s important to place a contact information for readers or potential advertisers to get in touch with you. For a formal and better communication, it’s better for them to contact you via email since it’s much easier to manage and keep track of the communication.
There are two ways to encourage others to contact you via email, either by providing a contact form or by displaying your email address on the contact form page. In this article, we’ll show you how to prevent your email from being spammed by email harvester using a less-known WordPress antispambot fuction.
WordPress antispambot Function
For example, to display your email on any post, you may wrap your email in the antispambot function:
<?php antispambot( 'john@domain.com' ) ?>
What the function does is convert the email address to an HTML entities. To make it even easier to use the function in any post, we may use a shortcode. First, we need to register a shortcode that can be used in our site. Simply put the following code in functions.php
file or even better, in your site’s functionality plugin.
Then, whenever you want to display an email address in your post, simply wrap the email in the [email]
shortcode. Example: [email]john@domain.com[/email]
Safer Email Link Plugin
For non-tech savvy users, there’s a plugin called Safer Email Link plugin. This plugin will add a button in the post editor to help you quickly add the shortcode to your post.
Once the plugin is activated, you’ll see a new button in the TinyMCE editor. Clicking on it will insert the [sf_email][/sf_email]
shortcode to the post editor. Then, simply insert your email between the opening and closing shortcode like [sf_email]john@domain.com[/sf_email]
We hope this tutorial helped you to avoid your email address being spammed in WordPress. Feel free to subscribe to our RSS feed to get latest WordPress tutorials straight to your mailbox or RSS reader.
I tried a similar plugin to achieve this effect but I found that when someone copied the email, in order to paste it into their email client or store it elsewhere it copied the characters used for obfuscation rather than the actual email address.
Do you know if that happens with the above methods?
Thanks.
Hey Joe,
We tried the Safer Email Link plugin and it copied the actual text, not the encoded text.
Thanks for the info. I will give it a try then.
Cheers, Joe
Here’s a question for you,
The antispambot function is publicly available with a very simple encoding pattern (converts to HTML entities). Doesn’t it reason then that most spammers have likely accounted for this and can simply check to unencode any email addresses? Definitely a good basic safeguard, but by no means safe - right? Or am I missing something?
Hi Mickey,
Interesting question. I’m not aware of this but I guess you’re right. Since the HTML will be prefix with “mailto” text, I guess the harvester will be looking for this word instead and grab whatever text next to it (which can easily be decoded)