was successfully added to your cart.

Protecting Email Address against Spambot

By October 2, 2015 Our Blog No Comments

The Spambots work by scanning the source code of your site, looking for your email addresses and following links to other pages. Email addresses are fairly easy to pick out due to their formatting and their use of the “mailto” URL function. So, how do you deter the majority of bots?

Use the following formula in the template/theme:

<?php echo antispambot('max.musterman@example.com'); ?>

Obviously you need to replace with your email address.

If you want to use it in the editor area, you have to write function which allows shortcode insertion.
Copy the following code in the functions.php of the theme:

* 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 '<a href="mailto:' . antispambot( $content ) . '">' . antispambot( $content ) . '</a>';
add_shortcode( 'email', 'wpcodex_hide_email_shortcode' );
add_filter( 'widget_text', 'shortcode_unautop' );
add_filter( 'widget_text', 'do_shortcode' );

To use this in your WordPress Content area, posts and widgets all you have to do is wrap your email address in a short code.


Leave a Reply

Click to Get Full Access to our entire collection for only $69! Get Access Today