Change or Translate Text on a WordPress Theme

You may want to replace a line or two of text on your WordPress Theme. You can easily change or translate a text by adding this code on your WordPress Functions. If what you’re after is to actually translate the entire theme and not just a couple of words then read this post instead: How to add Language Files on a WordPress Child Theme

This code makes use of the gettext function. Replace Old Text with the string you want to change. This is case-sensitive so type it exactly as you see it on your WordPress Theme. Replace New Translation with your new text replacement. You can leave it blank if you want to remove the original text.

To change or translate a single string, add this code on your functions.php.

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

Using arrays can be an efficient way to change multiple text. This one isn’t case-sensitive. To change or translate multiple strings, add this code on your functions.php. If needed, follow the code pattern to add more.

function ra_change_translate_text_multiple( $translated ) {
	$text = array(
		'Old Text 1' => 'New Translation 1',
		'Old Text 2' => 'New Translation 2',
		'Old Text 3' => 'New Translation 3',
	);
	$translated = str_ireplace(  array_keys($text),  $text,  $translated );
	return $translated;
}
add_filter( 'gettext', 'ra_change_translate_text_multiple', 20 );

Share This Post

33 Comments

Add a Comment
  1. I’ve used this coding in the past to successfully change 4 strings on my wp installation. Those changes are still working.

    I tried to use the coding to change the comment moderation notice wording. But it refuses to change. Below is the coding I have used in my child of twentytwelve theme. What have I done incorrectly?

    <pre>
    function change_some_text4( $change_text4 ) {
    if ( $change_text4 == 'Your comment is awaiting moderation' )
    {
    $change_text4 = 'All comments are moderated and, if approved, will appear as soon as possible.';
    }
    return $change_text4;
    }
    add_filter( 'gettext', 'change_some_text4', 20 );</pre>

Leave a Reply

Please write your comments in english. I delete anything that even remotely resembles spam.

Note: When posting code, enclose it in pre and code tags.
e.g. Add code here