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.

Ready to get started?

Tell us about your needs

Let us lead the way. We’ll help you select a top tier development partner. We’ll train your developers, operations, infrastructure, and editorial teams. We’ll coarchitect your deployment processes. We will provide live support for peak events. We’ll help your people avoid dark alleys and blind corners, and reduce wasted cycles.