FriendlyWP
10/26/2013 - 12:58 AM

Mailto email obfuscation shortcode. For anti-spam (spam-bots, spam fix, email mailto).

Mailto email obfuscation shortcode. For anti-spam (spam-bots, spam fix, email mailto).

/*  SHORTCODE FOR EMAIL OBFUSCATION
 *  usage: [email]myaddress@domain.com[/email]
 *  OR: [email address="myaddress@domain.com"]Contact Us[/email]
*/
add_shortcode('email', 'emailbot_ssc');
function emailbot_ssc($atts, $content = null) {
    extract( shortcode_atts( array(
        'address' => '',
    ), $atts ) );

    ob_start();

    if ( !isset($atts['address']) ) {
    	$address = $content;
    } else {
    	$address = $atts['address'];
    }

    $email = '<a class="email_link" href="mailto:'.antispambot($address).'" target="_blank">';
    $email .= antispambot($content);
    $email .= '</a>';
 	
 	$output = ob_get_clean();
    return $email . $output;
}