How can I substitute a word across the entire site, backend, and front end?
I wanted to make these substitutions:
'existing word' => 'new word'
'Partner User' => 'Spa Owner',
'Hotel' => 'Spa',
'Hotels' => 'Spas',
'hotel' => 'spa',
'hotels' => 'spas',
'Hotel(s)' => 'Spa(s)',
'hotel(s)' => 'spa(s)'
I tried adding this to my functions.php file:
function mycustom_filter_gettext( $translated, $original, $domain ) {
// This is an array of original strings
// and what they should be replaced with
$strings = array(
'Partner User' => 'Spa Owner',
'Hotel' => 'Spa',
'Hotels' => 'Spas',
'hotel' => 'spa',
'hotels' => 'Spas',
'Hotel(s)' => 'Spa(s)',
'hotel(s)' => 'spa(s)'
'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 );
It works only in some places in the admin backend and a couple of places in the front end, but not site-wide.
There is a language file... is it possible the language file is loading after the functions.php is loaded and changing the texts back?
Would it be a better idea to modify the language file with Poedit?
There has to be thousands of instances of the words I want to change across the entire site. Changing them all manually would be very tedious and time-consuming.
I was hoping a function substituting text strings would be easier to implement, and would not be affected by theme updates when put into a child theme functions.php.
Again... it partially works, but I need these translations across the entire site. I don't know how Poedit works (I've never used it)... would I manually have to change thousands of results manually?
Does anyone know of a solution that would work?