Skip to content

Instantly share code, notes, and snippets.

@stuartduff
Last active July 17, 2022 14:34
Show Gist options
  • Save stuartduff/3144286 to your computer and use it in GitHub Desktop.
Save stuartduff/3144286 to your computer and use it in GitHub Desktop.
WordPress Translate Text testing Snippet - this snippet when added to a themes functions.php file will let you test if the Localization of a word or text string is taking effect and changing within a theme or plugin without using the translation .MO and .PO files.
function translate_text( $translated ) {
// The first parameter is the original text, the second parameter is the changed text.
$translated = str_ireplace( 'Choose and option', 'Select', $translated );
// Returns the translated text
return $translated;
}
add_filter( 'gettext', 'translate_text' );
add_filter( 'ngettext', 'translate_text' );
@pablosfc
Copy link

Thank you @stuartduff ! This snippet when added with Code Snippet plugin in wordpress is working fine too. Then I didn´t to edit funcions.php.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment