Skip to content

Instantly share code, notes, and snippets.

@hearvox
Created February 24, 2018 20:12
Show Gist options
  • Save hearvox/cd9c3e43f79d83537ce355ac44c12541 to your computer and use it in GitHub Desktop.
Save hearvox/cd9c3e43f79d83537ce355ac44c12541 to your computer and use it in GitHub Desktop.
WordPress: Shortcode to hide email address from Spam Bots
<?php
/**
* Shortcode to hide email address from Spam Bots.
*
* Example: [email]me@mysite.com[/email]
*
* @uses antispambot() Wordpress native function
*
* @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 my_email_hide_shortcode( $atts , $content = null ) {
if ( ! is_email( $content ) ) {
return;
}
return '<a href="mailto:' . antispambot( $content ) . '">' . antispambot( $content ) . '</a>';
}
add_shortcode( 'email', 'my_email_hide_shortcode' );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment