Log in to WordPress using an Email Address
by c.bavota | Posted in Tutorials | 26 comments
Dec 28 2011
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
I keep a pretty good tracking of my Id log info, but once in a while I still lose them. Looks like a cool functionality! Going to give it a try soon. Thank you!
I appreciate it tremendously.
It’s very simple. Super!!
Thank you
I had this problem a few months ago, that is how I found your blog. I used WP plugin to take of it. From security stand point is it better to do it your way, hard code, or use a plugin?
Thank you for you!
These functions are great! I was a big Drupal believer but this stuff is too great. I was looking for something like this with a plugin but being able to log into my website with my email from this function is great!
Thanks!
I’m building a theme where I’m trying not do depend on plugins as much as possible and this eliminated the need for another plugin. Thanks again!
Mike
Very nice and useful article.Thanks for sharing
Thanks for sharing this … i was using a plugin for this func, but I will switch to this small bit of code