Using gettext on wp-login.php won't change "Back to site name" text

I'm attempting to change the "← Back to sitename" text on the wp-login.php page using gettext but not having much luck.

No matter what I try it doesn't seem to want to work, although I've had success changing the "Lost your password?" text using the same method.

Here is my latest snippet

function custom_login_text ( $text ) {

    if (in_array( $GLOBALS['pagenow'], array( 'wp-login.php', 'wp-register.php' ) )) {

        if ($text == 'larr; Back to %s'){$text = 'Test';}
        return $text;

    }

}
add_filter( 'gettext', 'custom_login_text' );

I've also tried directly using ← Back to Site Name but that didn't work either. Am I missing something?

Any tips would be appreciated.

Topic wp-login-form Wordpress

Category Web


Change text "Back to site name" on 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' );

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' );

Your snippet works fine for me.

Although, you should be testing the second argument, rather than the first. See the codex. You are testing for text that may already have been translated, so your string comparison could fail.

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

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.