Convert email addresses to HTML entities and block spam bots

antispambot() is a native WordPress function that will convert email addresses into HTML entities in order to block spam bots.

echo antispambot( 'john.doe@domain.com' );

This great little snippet from the WordPress codex will let you use antispambot() in a simple shortcode. Just add this snippet to the functions.php file of your WordPress theme. Then, wrap this shortcode around an email address in any post to convert the email address into HTML entities: [email]john.doe@domain.com[/email] Enjoy!

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

Comments  Leave a Reply

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!