How to make your emails in WordPress content more secure

Securing emails is crucial for every site. WordPress has a beautiful solution for securing your email links. This core function is called antispambot(). With a simple shortcode, which you can add to a custom plugin or your theme function.php you can use this function.

After processing a email address by the antispambot function:

echo antispambot('');

The output in HTML is like this:

But normal visitors see this:

Use Antispambot in a shortcode

We use the following code in our functions.php to make secure emails possible for all our clients. If you want to use it, please feel free to copy paste the following code to your own functions.php or in a custom plugin.

/* ------------------------------------------------------------------*/
/* ------------------------------------------------------------------*/

function wpf_secure_mail( $atts,$content=null ) {
shortcode_atts( array(
"mailto" => ''
), $atts)

if(!$content) $content=$mailto;

$mailto = antispambot( $mailto );
$content = antispambot( $content );

return '<a href="mailto:' . $mailto . '">' . $content . '</a>';

if ( function_exists('add_shortcode') )
add_shortcode('email', 'wpf_secure_mail');


To use this shortcode use this in your WordPress content:

[email mailto=""]
[email mailto=""]Click here[/email]

Just post your comment if you’ve any questions about this WordPress tip or if you see a mistake.