在wp-login.php上使用getText不会更改“Back to Site Name”文本

时间:2017-01-10 作者:Syrehn

我正在尝试更改“← 使用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 但这也没用。我错过什么了吗?

如有任何提示,将不胜感激。

3 个回复
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 );

SO网友:prosti

Why not like this:

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_with_context\', \'custom_login_text\' );
SO网友:dev

在wordpress上更改文本“返回站点名称”

function change_go_to ($text1) {

             if ($text1 == \'← Back to %s\'){
                 $text1 = \'Go to Website\';

             }
                    return $text1;
             }
    add_filter( \'gettext_with_context\', \'change_go_to\' );

相关推荐