-
-
Save pcaWeb/c86dc77099bc47b74474 to your computer and use it in GitHub Desktop.
WordPress: Obfuscates email addresses from spam bot.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Hides email addresses from spam bot. | |
* | |
* @param array $atts The various options. The only required option is "address". | |
* @example [email address="name@example.com"] | |
*/ | |
function ubnsc_email( $atts ) { | |
extract( shortcode_atts( array( | |
'type' => 'email', | |
'address' => '', | |
'class' => '', | |
'subject' => '', | |
'text' => '', | |
), $atts ) ); | |
switch ( $type ) { | |
case 'email' : $protocol = 'mailto:'; break; | |
case 'jabber' : $protocol = 'xmpp:'; break; | |
} | |
if ( $class ) $css = 'class="' . esc_attr( $class ) . '" '; | |
if ( $subject ) $subject = '?subject=' . esc_attr( $subject ); | |
if ( $text == '' ) $text = antispambot( $address ); | |
$output = '<a ' . $css . 'href="' . $protocol . antispambot( $address, 1 ) . $subject . '">' . $text . '</a>'; | |
return $output; | |
} | |
add_shortcode('email', 'ubnsc_email'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment