NB: Make sure you do a back up of your theme, files and database before attempting the tutorials
Last modified : Sep 22 2022
Estimated reading time : 1 minute, 30 seconds - 122 words
Share the post "Protect your Emails against Robot Spammers"
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' );