title

Use gettext, ngetext to replace array of words in wp admin

 

Use gettext, ngetext to replace array of words in wp admin

10 Mai 2013, Posted by antoine in

Simple but useful method using gettext, ngetext filter to replace an entire array of words within the wordpress admin. Just update the array key with the item you wish to replace and the array value with the text to replace it with. Add this snippet to the functions.php of your wordpress theme.

add_filter(  'gettext',  'wps_translate_words_array'  );
add_filter(  'ngettext',  'wps_translate_words_array'  );
function wps_translate_words_array( $translated ) {
     $words = array(
                        // 'word to translate' = > 'translation'
                        'Posts' => 'Article',
                        'Post' => 'Articles',
                        'Pages' => 'Stuffing',
                        'Media' => 'Upload Images',
                        'Links' => 'Blog Roll',
                    );
     $translated = str_ireplace(  array_keys($words),  $words,  $translated );
     return $translated;
}