Title: WordPress antispambot?
Last modified: October 31, 2018

---

# WordPress antispambot?

 *  Resolved [Alwin](https://wordpress.org/support/users/wp-opti/)
 * (@wp-opti)
 * [7 years, 9 months ago](https://wordpress.org/support/topic/wordpress-antispambot/)
 * Hello, I like to publish my email address on my website but want to protect it
   from spammers. I have read about the build in function called antispambot. I 
   like to use that instead of a plugin.
 * [https://codex.wordpress.org/Function_Reference/antispambot](https://codex.wordpress.org/Function_Reference/antispambot)
 * I don’t know exactly how to set this up. Maybe like this:
 * 1 – add this code to my function.php file:
 *     ```
       /**
        * 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' );
       ```
   
 * 2 – Change the email links on my contact page into a sort code[email]john.doe@
   mysite.com[/email]
 * Is that all?
 * Thank you very much for your help!
    -  This topic was modified 7 years, 9 months ago by [Jan Dembowski](https://wordpress.org/support/users/jdembowski/).
    -  This topic was modified 7 years, 9 months ago by [Jan Dembowski](https://wordpress.org/support/users/jdembowski/).

Viewing 7 replies - 1 through 7 (of 7 total)

 *  [Stefano](https://wordpress.org/support/users/madking-web-design/)
 * (@madking-web-design)
 * [7 years, 9 months ago](https://wordpress.org/support/topic/wordpress-antispambot/#post-10833485)
 * Hey [@alwin](https://wordpress.org/support/users/alwin/) !
    [Anti-SpamBot](https://wordpress.org/plugins/antispambot/)
   plugin, easily can do the trick for you. The plugin using built-in WordPress 
   Codex functionality. [Here are some examples](https://codex.wordpress.org/Function_Reference/antispambot#Examples)
   in case that you want to build your own functionality!
 *  Thread Starter [Alwin](https://wordpress.org/support/users/wp-opti/)
 * (@wp-opti)
 * [7 years, 9 months ago](https://wordpress.org/support/topic/wordpress-antispambot/#post-10833507)
 * Hello Stefano,
 * I like to do it without needing an (extra) plugin.. 🙂
 * The link you send me is the same as in my own post.
 * How to set it up, that is my question. First add the code to my functions.php
   and then use the short codes instead of my usual mailto links?
 * ThaNk you,
    Alwin
 *  [Stefano](https://wordpress.org/support/users/madking-web-design/)
 * (@madking-web-design)
 * [7 years, 9 months ago](https://wordpress.org/support/topic/wordpress-antispambot/#post-10833557)
 * Exactly, you need to add the code into your theme’s function.php
    In that case
   I would suggest to use a [childtheme](https://codex.wordpress.org/Child_Themes)
   and make sure also to have a recent backup and FTP(or SFTP) access, just in case
   something goes wrong.
 *  Thread Starter [Alwin](https://wordpress.org/support/users/wp-opti/)
 * (@wp-opti)
 * [7 years, 9 months ago](https://wordpress.org/support/topic/wordpress-antispambot/#post-10834016)
 * I have added this code to my functions.php in my child theme:
 * /**
    * Hide email from Spam Bots using a shortcode. * * [@param](https://wordpress.org/support/users/param/)
   array $atts Shortcode attributes. Not used. * [@param](https://wordpress.org/support/users/param/)
   string $content The shortcode content. Should be an email address. * * [@return](https://wordpress.org/support/users/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( ‘[%s](https://wordpress.org/support/topic/wordpress-antispambot/%s?output_format=md)‘,
   esc_url( $email_link, array( ‘mailto’ ) ), esc_html( $content ) );
    } add_shortcode(’
   email’, ‘wpcodex_hide_email_shortcode’ );
 * I have not changend anything in this code. That is correct?
 * Then I have added the shortcode in my wordpress text area.
 * Now when I look at the website page I see my email address and when I put the
   mouse over the email address I still see normal mailto:info@mydomain.com link
   under in the browser. Is that how it suposed to be?
 * When I look in the source code I see that my email address is indeed encoded.
 * Everything okay like this?
 *  [Stefano](https://wordpress.org/support/users/madking-web-design/)
 * (@madking-web-design)
 * [7 years, 9 months ago](https://wordpress.org/support/topic/wordpress-antispambot/#post-10834267)
 * If it’s encoded, then I thing mission accomplished..Should appear as a normal
   email address to anyone using web browser, but most bots will not be able to 
   identify it.
 *  Thread Starter [Alwin](https://wordpress.org/support/users/wp-opti/)
 * (@wp-opti)
 * [7 years, 9 months ago](https://wordpress.org/support/topic/wordpress-antispambot/#post-10834302)
 * Great! Thank you for your help!
 * 🙂
 *  [Stefano](https://wordpress.org/support/users/madking-web-design/)
 * (@madking-web-design)
 * [7 years, 9 months ago](https://wordpress.org/support/topic/wordpress-antispambot/#post-10896137)
 * Cool! 😉

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘WordPress antispambot?’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 7 replies
 * 2 participants
 * Last reply from: [Stefano](https://wordpress.org/support/users/madking-web-design/)
 * Last activity: [7 years, 9 months ago](https://wordpress.org/support/topic/wordpress-antispambot/#post-10896137)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
