[wp-hackers] Hiding email address output

Robert Lusby nanogwp at gmail.com
Mon Jan 24 09:47:41 UTC 2011


Hello,

Looking at automatically hiding email addresses across posts/pages within
our WordPress install.

We have the function below, (kindly borrowed from Manakor). What would be
the best hook/filter to call this function?

Obviously it needs to run against every bit of content outputted:
"tep_rewrite_email($content)".

Keen to avoid output buffering, as it causes a noticeable load time increase
across our site.

Thanks!

Robert

1function tep_rewrite_email($content) {
2  $email_patt =
'([A-Za-z0-9._%-]+)\@([A-Za-z0-9._%-]+)\.([A-Za-z0-9._%-]+)';
3  $mailto_pattern = '#\<a[^>]*?href=\"mailto:\s?' . $email_patt .
'[^>]*?\>[^>]*?<\/a\>#';
4  $rewrite_result = '<span class="mailme">\\1 AT \\2 DOT \\3</span>';
5
6  $content = preg_replace($mailto_pattern, $rewrite_result, $content);
7  $content = preg_replace('#' . $email_patt . '#', $rewrite_result,
$content);
8
9  // remember to add return here
10  return $content;
11}


More information about the wp-hackers mailing list