Wordpress 替换 admin 中所有出现的字符串 [英] Wordpress replace all ocurrances of the string in admin
问题描述
我正在尝试更改 Wordpress Admin 中各个位置的单词,例如,将仪表板"的名称更改为其他名称,但我希望它在整个 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!
推荐答案
把这段代码放到你子主题的function.php文件中:
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.
这篇关于Wordpress 替换 admin 中所有出现的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!