Dec
28
2011
Log in to WordPress using an Email Address
I needed to figure out how to allow a user to use either their username or email address to log into WordPress. It took a bit of rooting around but the final piece of code ended up being pretty simple.
function login_with_email_address($username) { $user = get_user_by_email($username); if(!empty($user->user_login)) $username = $user->user_login; return $username; } add_action('wp_authenticate','login_with_email_address'); |
Place that in your functions.php file and you will be able to sign into your WordPress site using an email address or by default, the username.



worked great…thanks!
Works fine here too. Thanks for the tip. Wonder why it can’t be made into the WordPress core. It is easy to remember the email than the username.
Works great. Thanks for the effort
Hey Bavotasan, debug says get_user_by_email is deprecated since 3.3, in favor of get_user_by(‘email’). Really great tip nonetheless!
Thanks for pointing that out.
I have been looking for a good login security solution.I think this together with pie register might be the perfect fix.thanks for making it look so easy.
works like magic, wonderful i say!!! I know where to go incase i run into some trouble. Thanks again
I was seraching for that so long. Finally i can integrade this on my site. Thanks a lot
Thanks this function saves us a lot of time for our blog management. Much appreciated.
Thanks for sharing it’s really useful.
useful trick, thanks!
Thats awesome, I hate when sites don’t id or email. Because you always remember your email address but ID’s are often taken so your forced to use something else.
GJ.
works great on my site with a child theme – classi. thanks