The Result
Username
You can declare the form field value global and prefill it.
This will override any setting done via the "Remember me"-Checkbox.
/**
* Changes the default user name to "DEMO"
*
* @return string $user_login
*/
function login_form_username()
{
global $user_login;
return $user_login = 'DEMO';
}
add_action( 'login_head', 'login_form_username' );
Password
I found nothing that you can use to prefill it, so I'd add a note. Gladly/Sadly there's the whole set of stylesheets for the admin UI available. So .wrap
in connection with h2
gives a nice styling. The function is hooked to the additional fields hook for the admin hook. The priority is 0
to set it above additional fields.
/**
* Adds a note beyond the user login name & password field
*
* @return string
*/
function login_form_note()
{
print '<div class="wrap"><h2 style="text-align: center;">The Password is "DEMO"</h2></div>';
}
add_action( 'login_form', 'login_form_note', 0 );
Security: Hide Errors
As someone would get a visual proof that he entered an existing user name by default, I'd add the following to your functions.php file, to avoid telling if the username was guessed right:
/**
* Hide wrong login names
*
* @return string
*/
function no_login_error()
{
return __( 'Wrong Credentials.' );
}
add_filter( 'login_errors', 'no_login_error' );
Other filters
Notes:
- If you want to replace other stuff like styles, then you can use the
login_enqueue_scripts
hook.
- You can also replace the link behind the logo using the
login_headerurl
filter that filters the url. The link title
can be replaced using login_headertitle
. Both trigger for multisite as well a single site setups.
- The login message can be changed using the
login_message
filter.