Created
March 18, 2013 10:44
-
-
Save olssonm/5186338 to your computer and use it in GitHub Desktop.
Spam is shit. If you entity-encode your e-email adress those annoying little robots will have a more difficult time getting to it, and it stills allow you to show it as plain text. This an encoder for wordpress (just put it in your functions.php). Example: example@example.com would become: example@e&#…
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
add_shortcode('email', 'encodeEmail'); | |
function encodeEmail($attr) { | |
extract(shortcode_atts(array( | |
'adress' => 'nothing', | |
'text' => 'nothing', | |
), $attr)); | |
function encodeToEntity($str) { | |
$str = mb_convert_encoding($str , 'UTF-32', 'UTF-8'); | |
$t = unpack("N*", $str); | |
$t = array_map(function($n) { return "&#$n;"; }, $t); | |
$t = implode("", $t); | |
return $t; | |
} | |
return '<a href="' . encodeToEntity('mailto:' . $attr['adress']) . '">' . encodeToEntity($attr['text']) . '</a>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment