我正在尝试更改“← 使用gettext返回wp-login.php页面上的“sitename”文本,但运气不太好。
不管我怎么尝试,它似乎都不想工作,尽管我成功地更改了“丢失了密码?”使用相同方法的文本。
这是我的最新片段
function custom_login_text ( $text ) {
if (in_array( $GLOBALS[\'pagenow\'], array( \'wp-login.php\', \'wp-register.php\' ) )) {
if ($text == \'← Back to %s\'){$text = \'Test\';}
return $text;
}
}
add_filter( \'gettext\', \'custom_login_text\' );
我也尝试过直接使用
← Back to Site Name 但这也没用。我错过什么了吗?
如有任何提示,将不胜感激。
SO网友:vancoder
你的代码片段对我很有用。
尽管如此,您应该测试第二个参数,而不是第一个参数。See the codex. 您正在测试可能已经翻译的文本,因此字符串比较可能会失败。
function custom_login_text ( $translated_text, $untranslated_text ) {
if (in_array( $GLOBALS[\'pagenow\'], array( \'wp-login.php\', \'wp-register.php\' ) )) {
if ( \'← Back to %s\' == $untranslated_text ){
$translated_text = \'Test\';
}
return $translated_text;
}
}
add_filter( \'gettext\', \'custom_login_text\', 20, 2 );