In this tutorial, you will learn how to add anti-spam bot in your website.
- Create a shortcode.php in your ftp and include it in our functions.php.
- In your shortcode.ph add this code.
function sm_antispam_script_sc($atts, $content){
extract( shortcode_atts( array(
"email" => ''
), $atts));
ob_start();
?>
<?php
$email = antispambot($email);
return '<a href="mailto:' . $email . '">' . $email . '</a>';
// return do_shortcode( ob_get_clean() );
}
add_shortcode('sm_antispam_script', 'sm_antispam_script_sc');
note: by adding this code we will then have this shortcode [sm_antispam_script email=”youremail@gmail.com”]
- After creating your shortcode, go to your post/page where you displayed your email and replace it with shortcode block.
- Then in your shortcode black add this shortcode [sm_antispam_script email=”youremail@gmail.com”] and then click save then you are done.
Here is how you can check if the code above is working.
- Go to the page where you added your shortcode.
- In your keyboard click CTRL+U
- Find the code of your email and you will see that your email has been converted to a random character to prevent spam. (see screenshot below)

That is the end of the tutorial. If you have any questions, just contact the author of this post.