Last active
December 16, 2015 00:39
-
-
Save intelliweb/5349548 to your computer and use it in GitHub Desktop.
WP: encodes email address by converting each character into HTML entities to help protect against spambots
This file contains hidden or 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 | |
// WordPress function that encodes an email address (and adds mailto: link) | |
echo antispambot('[email protected]', 1); | |
?> | |
<?php | |
// Shortcode to encode email address in a mailto: link | |
function protect_email_address( $atts , $content=null ) { | |
for ($i = 0; $i < strlen($content); $i++) $encodedmail .= "&#" . ord($content[$i]) . ';'; | |
return '<a href="mailto:'.$encodedmail.'">'.$encodedmail.'</a>'; | |
} | |
add_shortcode('mailto', 'protect_email_address'); | |
/* | |
Then use this shortcode format to 'encode' it: | |
[mailto][email protected][/mailto] | |
*/ | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment