0

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 == '← 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.

  • So, have you found my answer helpful? I tested on my end and it works. @Syrehn. – prosti Jan 16 '17 at 8:50
0

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 );
  • Thanks for the reply and the codex link. :) I was originally testing my snippet using the Code Snippets plugin and while it was changing the "Lost password" text it wasn't changing the "Back to" text. I just tossed my original snippet into my theme's functions.php and it's working as intended. I did test your snippet as well inside my theme's functions.php but it breaks my WP admin (all the text vanishes). I'll do a bit more playing to follow the codex. – Syrehn Jan 11 '17 at 0:44
0

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.