Skip to content

Instantly share code, notes, and snippets.

@jdelia
Created March 8, 2017 15:21
Show Gist options
  • Save jdelia/32b2abf809e8df347c970cc37bc5381a to your computer and use it in GitHub Desktop.
Save jdelia/32b2abf809e8df347c970cc37bc5381a to your computer and use it in GitHub Desktop.
<?php
/**
* Creates a link for email and then hide email address from Spam Bots in HTML using a shortcode.
* [email]hello@email.com[/email]
*
* @param array $atts Shortcode attributes. Not used.
* @param string $content The shortcode content. Should be an email address.
*
* @return string The obfuscated email address.
*/
function jdd_hide_email_shortcode( $atts, $content = null ) {
if ( ! is_email( $content ) ) {
return;
}
return '<a href="mailto:' . antispambot( $content ) . '">' . antispambot( $content ) . '</a>';
}
add_shortcode( 'email', 'jdd_hide_email_shortcode' );
// Enable shortcodes in text widgets
add_filter( 'widget_text','do_shortcode' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment