// Coding directly into a page template, you can use the built-in WordPress function below:
antispambot( "youremail@yoursite.com" );
// A way to make use of the antispambot() function within posts and pages content using a shortcode
// EMAIL ENCODE SHORTCODE
function encode_email_shortcode( $atts, $address = null ){
if( !is_email( $address ) ){
return;
}
$mailtoaddr = antispambot( $address );
$maillink = '<a href="mailto:';
$maillink .= $mailtoaddr;
$maillink .= ( isset( $atts['subject'] ) ? '?subject='.$atts['subject'] : '' );
$maillink .= '" target="_blank">';
$maillink .= ( isset( $atts['output'] ) ? $atts['output'] : $mailtoaddr );
$maillink .= '</a>';
return $maillink;
}
add_shortcode( 'email', 'encode_email_shortcode' );
/*
Code snippet above goes in your theme function.php
Use the following structure to safely display an email address in your post or page content:
[email]you@you.com[/email]
[email subject="Website Inquiry"]you@you.com[/email]
[email output="Click here to contact us"]you@you.com[/email]
[email output="Click here to contact us" subject="Website Inquiry"]you@you.com[/email]
*/