Skip to content

Instantly share code, notes, and snippets.

@olssonm
Created March 18, 2013 10:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olssonm/5186338 to your computer and use it in GitHub Desktop.
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&#…
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