› News › Web Development
 › Stop spam in WordPress: How to (Updated for 2020)
   -   3 March, 2020

Stop spam in WordPress: How to (Updated for 2020)

Photo by Pau Casals on Unsplash

This is a quick and super clean trick to stop spambots from scrapping all the emails off your website.

It converts selected email addresses characters to HTML entities to block spambots. Not all characters in the email address are converted: the selection is random and changes each time the function is called.

To use this in your WordPress Content area all you have to do it wrap the email address in a shortcode:

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

Insert this code into your child theme’s functions.php file to make it work:

/**
 * 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;
	}
	$content = antispambot( $content );
	$email_link = sprintf( 'mailto:%s', $content );
	return sprintf( '<a href="%s">%s</a>', esc_url( $email_link, array( 'mailto' ) ), esc_html( $content ) );
}
add_shortcode( 'email', 'wpcodex_hide_email_shortcode' );

Reference: https://codex.wordpress.org/Function_Reference/antispambot

CATEGORIES
POPULAR ARTICLES
How to install your beautiful new email signature
How to install your beautiful new email signature

Displaying a beautifully designed new email signature in your emails can help elevate your business and help your potential clients take you seriously. A custom-designed email signature can have a call to action to drive sales. It can be used to inform your clients on...

Are you eligible for a $3000 Small Business Recovery Grant?
Are you eligible for a $3000 Small Business Recovery Grant?

NSW eligible small businesses, not-for-profits, and other business types that have fewer than 20 Full Time Equivalent (FTE) staff (including non-employing businesses, such as sole traders) as at 1 March 2020 can apply for recovery grants from $500 to $3,000. There's...

5 Ways to Improve the SEO of your website
5 Ways to Improve the SEO of your website

Aussies like to be well informed before parting with their hard-earned cash. In Australia, 84% of consumers will check out research online before making a purchase or using your service. This means your website not only has to sell the right goods but also answer the...

TAGGED WITH

//

We want to hear what you think about this article, or what you would like us to write about next! Submit a comment below or write to us at hello@studiotwofold.com.au.
Studio Twofold provides creative design services and advice to growing Australian businesses to help them feel confident and kick goals. Learn more about us.

READ THESE NEXT

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Want to talk?

Our process begins with a conversation about your business and how we can help.