Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
//* Please do NOT include the opening php tag, except of course if you're starting with a blank file
function mycustom_filter_gettext( $translated, $original, $domain ) {
// This is an array of original strings
// and what they should be replaced with
$strings = array(
'Register' => 'Sign up',
'Confirm and go to payment page' => 'Complete registration',
'No events available...' => 'No upcoming classes at this time...',
'click here to add a new state/province' => 'click here to enter address outside US/Canada',
// Add some more strings here
// See if the current string is in the $strings array
// If so, replace its translation
if ( isset( $strings[$original] ) ) {
// This accomplishes the same thing as __()
// but without running it through the filter again
$translations = get_translations_for_domain( $domain );
$translated = $translations->translate( $strings[$original] );
return $translated;
add_filter( 'gettext', 'mycustom_filter_gettext', 10, 3 );

This comment has been minimized.

Copy link

eivind1984 commented Jan 15, 2015

Just a little heads up to peple running non-english installations: The strings in the $strings array needs to be the original english string, not the one that's already being translated. So, in my case, I wanted to change the phrase "Tilgjengelige billetter", but still had to put "Available tickets" in the $strings array to make it work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.