How to add filter to __() and _e()?

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.

Leave a Comment