Prevent Email Spam with WordPress AntiSpamBot Function

  • 6
spam

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('protectmy@email.com') ?>

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

This will output the email like this in the HTML:

&#106;&#111;h&#110;&#46;&#100;&#111;&#101;&#64;mysit&#101;.&#99;&#111;&#109;

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

john.doe@mysite.com

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

[email]john.doe@mysite.com[/email]

***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' );

Examples

/**
 * 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;
	}

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

6 Comments

Dara

November 17, 2016 at 3:29 am

Very informative

    naisim

    November 17, 2016 at 8:34 am

    Thank you Dara!

Johne55

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

    naisim

    December 21, 2016 at 4:12 am

    Thanks Q

Smithg176

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

    naisim

    December 21, 2016 at 4:13 am

    Thanks Q

Leave a Reply

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

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

14900394_1210512852328697_4210227613257262278_n
បច្ចេកទេសក្នុងការដាំម្ទេស

Close