Prevent your email-address from the spam bots in WordPress without any plugin

From the last several days I have lot of spam mails on the contact-us email address. After investigating, I have found several reasons: one of them is that I have place the email address on the contact page that was accessible by everyone include the spam bots also. Many Spam bots can find very easily your email address format using the several regular expression. So you need to protect your email address from the spam bots. If you have a wordpress site than you can use the antispambot() function to encrypt the email address.The function will encode the characters in your address to their HTML character entity.

If you are using template page directly then you can use the function like as:

echo antispambot("");

You can also specify the encoding type in antispamnot method by passing 0 or 1 as optional parameter. Use 0 to only allow decimal encoding ({) and 1 to also allow hex encoding (&x7B;).

Creating short code if you want to use this functionality in your post

You can also create the short code for this, for it you need to add the following function in your function file(function.php).

The ‘functions.php’ is a template file used by WordPress themes. The ‘functions.php’ file can be found in your theme’s folder. Please take a backup of your ‘function.php’ before making any change. If your theme doesn’t have a ‘functions.php’ file you can simply create a plain-text file named ‘functions.php’ and add it to your theme’s directory.

// Code from the Wordpress codex
function HideMail($atts , $content = null ){
	if ( ! is_email ($content) )
	return '<a href="mailto:'.antispambot($content).'">'.antispambot($content).'</a>';
add_shortcode( 'email','HideMail');

[Source: WordPress Codex]

Than you can use the this short code in any page or post like as:


You should check your site and make sure your email address is secure.