__() wp code example

Example 1: wordpress translate specific text php

function translate_specific_text( $translated_text ) {
	if ( $translated_text == 'Old Text' ) {
		$translated_text = 'New Translation';
	}
	return $translated_text;
}
add_filter( 'gettext', 'translate_specific_text', 20 );

Example 2: _e in wordpress

/*
If you want to echo the translated string, then you will be using _e and when you just want to have the translated string, then you will be using __.
*/

_e('this is a message', 'twentyfourteen');

echo __('this is a message', 'twentyfourteen');

Tags:

Php Example