wordpresscode-translation

Wordpress replace all ocurrances of the string in admin


I am trying to change the words for various places in Wordpress Admin, for example, change the name of "Dashboard" to something else, but I want it to change across the entire Admin - all the occurances. I tried searching through admin files and replacing words, but this is just too much time consuming. I don't need the words to be translatable, is there any way to do this? Thanks!


Solution

  • Put this code to the function.php file of your child theme:

    add_filter(  'gettext',  'dirty_translate'  );
    add_filter(  'ngettext',  'dirty_translate'  );
    function dirty_translate( $translated ) {
         $words = array(
                // 'word to translate' => 'translation'
                'Dashboard' => 'Foo',
                'Add new' => 'Bar'
         );
    $translated = str_ireplace(  array_keys($words),  $words,  $translated );
    return $translated;
    }
    

    Just replace the translations with your own. You can add as many translations as you need. I'm using this myself - Tested and works.