On the default WordPress login page, how do you change the label, "Username", to something else?
-
wordpress.stackexchange.com/a/289583/133699– devJan 29, 2018 at 13:16
4 Answers
I think this is a better alternative to the previous answer.
function login_function() {
add_filter( 'gettext', 'username_change', 20, 3 );
function username_change( $translated_text, $text, $domain )
{
if ($text === 'Username')
{
$translated_text = 'customLoginName';
}
return $translated_text;
}
}
add_action( 'login_head', 'login_function' );
-
-
1This is a fantastic answer. Personally, I would move the filter callback outside of the if block, but that's just me. Either way, the 20 is for priority (used for the order of callback execution) and the 3 is the number of accepted arguments the callback takes. Oct 11, 2012 at 15:45
-
Also, feel free to mark your own answer as accepted. I'm sure this will come in handy for anybody who has the same question you did. Oct 12, 2012 at 3:48
Simple & Short Solution
add_filter( 'gettext', 'register_text' );
function register_text( $translating ) {
$translated = str_ireplace( 'Username or Email Address', 'Your Custom Text', $translating );
return $translated;
}
It's worked for me. Using this functions.php code you can change any text.
add_filter( 'gettext', 'register_text' );
function register_text( $translating ) {
$translated = str_ireplace( 'Username or Email Address', 'Your Custom Text', $translating );
return $translated;
}
Thanks to @Mohammad Bilal
Recently I get into the same situation, while I need to put the translated string to change this login label and I previously try using jQuery but didn't work so I use javascript as below:
function login_script_function() {
?>
<script type="text/javascript">
window.addEventListener('DOMContentLoaded', (event) => {
console.log('DOM fully loaded and parsed'); // to test DOM ready
var label_user_login = document.getElementsByTagName('label')[0];
var label_user_pass = document.getElementsByTagName('label')[1];
label_user_login.innerText = "<?php _e('User Name', 'text-domain'); ?>";
label_user_pass.innerText = "<?php _e('Password', 'text-domain'); ?>";
});
</script>
<?php
}
add_action( 'login_head', 'login_script_function' );
I'm using this with the custom plugin and add the string translation with e.g. Poedit or Loco Translate