A little-known feature in WordPress is antispambot() from the wp-includes/formatting.php. It is a kind obfuscator of the email address. It doesn’t create a clickable mailto link. Our e-mail with antispambot in the source code looks like this:

Screenshot WordPress antispambot email

You cannot use this function in a post or page unless you installed the EXEC-PHP Pluging. Kai had the cool idea to use shortcodes for this. This function belongs in the function.php of your theme folder:

<?php
function wpe_secure_mail($atts) {
	extract(shortcode_atts(array(
		"mailto" => '',
		"txt" => ''
	), $atts));
	$mailto = antispambot($mailto);
	$txt = antispambot($txt);
	return '<a href="mailto:' . $mailto . '">' . $txt . '</a>';
}
 
if ( function_exists('add_shortcode') )
	add_shortcode('sm', 'wpe_secure_mail');
?>

This shortcode will be used to write in your post/page:

[sm mailto="foo@bar.com" txt="here is my mail"]
//or
[sm mailto="foo@bar.com" txt="foo@bar.com"]

Share/Save/Bookmark