Skip to content

Instantly share code, notes, and snippets.

@GaryJones
Created September 5, 2016 21:05
Show Gist options
  • Select an option

  • Save GaryJones/0dabf830e44099aa049747fa87c3374f to your computer and use it in GitHub Desktop.

Select an option

Save GaryJones/0dabf830e44099aa049747fa87c3374f to your computer and use it in GitHub Desktop.
Translate specific WP string.
<?php
// Untested, but should give you an idea.
add_filter( 'gettext', 'claire_rename_color_to_colour' );
/**
* Rename the exact WP string "Color" to "Colour".
*
* Doesn't affect non-exact strings.
*
* @link https://core.trac.wordpress.org/browser/tags/4.6/src/wp-includes/l10n.php#L105
*
* @param string $translation Translated text.
* @param string $orignal_text Text to translate.
* @param string $domain Text domain. Unique identifier for retrieving translated strings.
*/
function claire_rename_color_to_colour( $translation, $original_text, $domain ) {
// Target WP strings by excluding anything with a textdomain.
if ( ! is_null( $domain ) ) {
return;
}
if ( 'Color' === $original_text ) {
$translation = 'Colour';
}
return $translation;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment