Wordpress 替换管理中所有出现的字符串

Wordpress replace all ocurrances of the string in admin

我正在尝试更改 Wordpress Admin 中不同位置的单词,例如,将 "Dashboard" 的名称更改为其他名称,但我希望它在整个 Admin 中更改 - 所有出现的地方。我尝试搜索管理文件并替换单词,但这太耗时了。 我不需要可翻译的文字,有什么办法可以做到这一点?谢谢!

将此代码放入您的子主题的 function.php 文件中:

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;
}

只需将翻译替换为您自己的即可。您可以根据需要添加任意数量的翻译。我自己正在使用这个 - 经过测试并且有效。