Documentation Tips & Tricks Changing Core WordPress Strings

Changing Core WordPress Strings

One of the lesser used filters in WordPress is ‘gettext.’

All strings that use the WordPress translation functions are run through this filter after the translation occurs, enabling developers to manipulate any string in WordPress. VIP’s use this most commonly in the admin area.

Here’s some sample code to filter a few WordPress core strings:

function vipuppies_filter_gettext( $translated, $original, $domain ) {

	// This is an array of original strings
	// and what they should be replaced with
	$strings = array(
		'View all posts filed under %s' => 'See all articles filed under %s',
		'Howdy, %1$s' => 'Greetings, %1$s!',
		// Add some more strings here

	// See if the current string is in the $strings array
	// If so, replace it's translation
	if ( ! empty( $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', 'vipuppies_filter_gettext', 10, 3 );

Note that this only applies to WordPress core strings. Anything in your own VIP themes or plugins can be changed directly in the files themselves.

Documentation is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.