NB: Make sure you do a back up of your theme, files and database before attempting the tutorials

Easy

---- Last modified : Sep 22 2022

Estimated reading time : 1 minute, 30 seconds - 122 words

Robot Spammers scan websites in order to create spams. The first thing you need to do is configure your cPanel or request help from your web hosting company. Now that your emails are configured optimally, we will set up a function to block Robot Spammers.

Simply use is wherever you want with the Antispambot WordPress function:

<?php echo antispambot( 'info@monsite.com' ); ?>

Or convert it into a shortcode in your functions.php file:

function wpdocs_hide_email_shortcode( $atts , $content = null ) {
    if ( ! is_email( $content ) ) {
        return;
    }
    return '<a href="' . esc_html('mailto:' . antispambot( $content ) ) . '">' . esc_html( antispambot( $content ) ) . '</a>';
}
add_shortcode( 'email', 'wpdocs_hide_email_shortcode' );

Copy/paste the shortcode in the template(s) of your choosing.

<?php echo antispambot( 'info@monsite.com' ); ?>

Copy/paste the shortcode in the pages or widgets of your choosing

[email]info@monsite.com[/email]

If you’re using this shortcode in a widget, make sure to have the do_Shortcode filter for Widgets. If not, here it is:

add_filter( 'widget_text', 'shortcode_unautop' );
add_filter( 'widget_text', 'do_shortcode' );

Leave a Reply

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

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>