I would wish to add a filter to _e() and __() functions. The filter is FilterTextOfEmail(). This will basically detect any emails and add anti-spam method to it.

I assume, the function for filtering should look like:

function my_wp_text_email_filtering ($content) {
    return FilterTextOfEmail($content)

But how to call it?

  • Could you provide more context on what is you're trying to archieve? Is FilterTextOfEmail an example function name, or does that function literally exist? More details and clarification of the question please..
    – t31os
    Dec 21 '11 at 21:54

The filter name is gettext, and you would add it like this:

add_filter( 'gettext', 'my_wp_text_email_filtering', 10, 3 );

function my_wp_text_email_filtering( $translated, $text, $domain ) {
    return FilterTextOfEmail( $translated );

The $text argument is there also in case you want to access the pre-translated text.

  • Thank you for answering, works great. However, what would be the filter for the the_content() as it appears, __() and _e() don't automatically apply for that. Dec 22 '11 at 11:23
  • Not sure what you're asking here? You just want to apply the same filter to the_content? Wouldn't add_filter( 'the_content', 'FilterTextOfEmail' ); work for that? Dec 22 '11 at 19:37

You have to filter 'gettext'. See this answer for an example.

Always check the textdomain parameter to avoid conflicts with plugins and themes.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.