Skip to content

Instantly share code, notes, and snippets.

Last active Apr 20, 2021
What would you like to do?
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' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment