Beginner's Guide for WordPress - Start your WordPress Blog in minutes.
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
WordPress Plugins
View all Guides

Prevent Email Spam with WordPress AntiSpamBot Function

Last updated on by
Special WordPress Hosting offer for WPBeginner Readers
Prevent Email Spam with WordPress AntiSpamBot Function

We recently wrote an article about about how to encrypt emails in WordPress with Cryptx. And as useful as this plugin is, there is actually another way to do this that doesn’t involve any plugin. One of our users pointed us to the WordPress Codex. Although most people don’t know, there is a function in WordPress called antispambot. This function essentially lets you hide your email address by converting every character to an HTML entity.

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

<?php antispambot('') ?>

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

Source: WordPress Codex

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi. Page maintained by Syed Balkhi.

WPBeginner's Video Icon
Our HD-Quality tutorial videos for WordPress Beginners will teach you how to use WordPress to create and manage your own website in about an hour. Get started now »


  1. jaffa says:

    @Ryan Lee Ball Could you please provide some further info? I would be interested in using this function in the way you have mentioned.


  2. jaffa says:

    @Ryan, could you provide somw further info please? Would be interested in using this code.


  3. Ryan Lee Ball says:

    With just a few lines of code in your functions.php file, you can add a content filter that makes use of WordPress’ inbuilt antispambot() function.

  4. WPBeginner - WordPress for Beginners says:

    The function doesn’t take an array. So you would have to use it twice for a different email address rather than separating by comma

  5. Kelley Daugherty Rao says:

    Great tip. If we want to protect more than one address, do we simply put a comma between the names?

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 comment policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.