Skip to content

Instantly share code, notes, and snippets.

@dannygsmith
Forked from jdelia/email-shortcode.php
Created September 10, 2017 01:19
Show Gist options
  • Save dannygsmith/b5d79fb4e722eb80b9aaca9c5465b5b9 to your computer and use it in GitHub Desktop.
Save dannygsmith/b5d79fb4e722eb80b9aaca9c5465b5b9 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