Skip to content

Instantly share code, notes, and snippets.

@alicolville
Last active March 28, 2019 09:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alicolville/acbcb1d91f889c65963f7099db784299 to your computer and use it in GitHub Desktop.
Save alicolville/acbcb1d91f889c65963f7099db784299 to your computer and use it in GitHub Desktop.
A snippet of code for replacing certain Weight Tracker words
/**
* Filter default WordPress translate functions to look for key Weight Tracker words and replace.
*
* @param $translation
* @param $text
* @param $domain
*
* @return string
*/
function wl_ls_cust_replace_words( $translation, $text, $domain ) {
/**
* Only look at Weight Tracker translations!
*/
if ( $domain !== 'weight-loss-tracker' ) {
return $translation;
}
$lookup = [
'kg' => 'Replacement word',
'Kg' => 'Replacement word',
'weight' => 'Replacement word',
'Weight' => 'Replacement word'
];
return ( false === empty( $lookup[ $text ] ) ) ? $lookup[ $text ] : $translation;
}
add_filter( 'gettext', 'wl_ls_cust_replace_words', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment