Prevent Email Spam with WordPress AntiSpamBot Function

  • 6

Prevent Email Spam with WordPress AntiSpamBot Function

Category : Programming

There are several ways to protect yourself against this and one method is to use a plugin. I suggest using the Function Reference/antispambot.

All you have to do is paste the code like this anywhere you want in your theme:

1<?php antispambot('') ?>

Don’t forget to replace “” with your own email and no spam bot will be able to find it.

This will output the email like this in the HTML:


But it will appear as a normal email address to anyone using a web browser:

***To use this in your WordPress Content area all you have to do it wrap it in a short code.


***You can also use this in a plain text widget if you add this filter to your function file as well.

add_filter( 'widget_text', 'shortcode_unautop' );
add_filter( 'widget_text', 'do_shortcode' );


 * Hide email from Spam Bots using a shortcode.
 * @param array  $atts    Shortcode attributes. Not used.
 * @param string $content The shortcode content. Should be an email address.
 * @return string The obfuscated email address. 
function wpcodex_hide_email_shortcode( $atts , $content = null ) {
	if ( ! is_email( $content ) ) {

	return '<a href="mailto:' . antispambot( $content ) . '">' . antispambot( $content ) . '</a>';
add_shortcode( 'email', 'wpcodex_hide_email_shortcode' );



November 17, 2016 at 3:29 am

Very informative


    November 17, 2016 at 8:34 am

    Thank you Dara!


December 14, 2016 at 10:15 pm

I have recently started a site, the info you provide on this website has helped me tremendously. Thanks for all of your time &amp work. The achievements of an organization are the results of the combined effort of each individual. by Vince Lombardi. efcaddgeafdf


    December 21, 2016 at 4:12 am

    Thanks Q


December 14, 2016 at 10:16 pm

I am now not certain the place you’re getting your info, however good topic. I needs to spend some time learning more or figuring out more. Thank you for magnificent info I was on the lookout for this information for my mission. dekdbgdddbggbdfe


    December 21, 2016 at 4:13 am

    Thanks Q

Leave a Reply

Read previous post:
Basic to fix Error missing in Wamp Server

I just write down what I have problem and done...