Created
February 24, 2018 20:12
-
-
Save hearvox/cd9c3e43f79d83537ce355ac44c12541 to your computer and use it in GitHub Desktop.
WordPress: Shortcode to hide email address from Spam Bots
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
<?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