Are you looking for a way to create a shortcode that obscures email links? This snippet will let you easily and quickly obscure an email address link to make it harder for spam bots to find your email address.
Instructions:
All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:
<?php // Obfusticate email addresses function obf_mail_shortcode( $atts , $content=null ) { for ($i = 0; $i < strlen($content); $i++) $encodedmail .= "&#" . ord($content[$i]) . ';'; return '<a href="mailto:'.$encodedmail.'">'.$encodedmail.'</a>'; } add_shortcode('mailto', 'obf_mail_shortcode'); ?>
You can wrap this shortcode around an email address to obscure the email address.
[mailto][email protected][/mailto]
Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly copy / paste code snippets in WordPress, so you don’t accidentally break your site.
If you liked this code snippet, please consider checking out our other articles on the site like: 24 best WordPress education themes and 8 best WordPress review plugins.
Thanks for the snippet but it returns an error:
Notice: Undefined variable: encodedmail in …/functions.php on line 274