Login with username or email address

MH Magazine Lite review - widget areas

Adding this snippet to the functions.php of your wordpress theme will let users login using an email address or a username. The second snippet will change the text on the login page from "username" to "username / email" but feel free to change the login text to anything you would like.

Try out Capture users last login date and time snippet for even more login awesomeness.

function login_with_email_address($username) {
	$user = get_user_by('email',$username);
		$username = $user->user_login;
	return $username;

function change_username_wps_text($text){
       if(in_array($GLOBALS['pagenow'], array('wp-login.php'))){
         if ($text == 'Username'){$text = 'Username / Email';}
                return $text;
add_filter( 'gettext', 'change_username_wps_text' );

Comments  Leave a Reply

  1. Working good………………….

  2. 25 WordPress Code Snippets for Enhanced Performance - ManageWP May 27, 2014 at 11:43 am

    […] Source […]

  3. Muito BOm , me ajudou bastante!

  4. OK, got it working. Just one little mistake on my side

  5. hi Kevin, it works great on the wordpress default login page. Any ideas on the code for a custom login widget. No need for the second code, i will manually change this in my widget. Many Thanks

  6. Debbie Campbell April 22, 2013 at 12:05 pm


  7. Works totally

  8. Oguzhan Isa Temiz November 17, 2012 at 4:23 pm

    So cool :D.

  9. Hey,. thanks for the snippet. Is their any snippet to disable viewing
    post drafts in “All Post” section. I mean Guest authors can only view
    their own post drafts, but not of others. Is it possible??

      1. Awesome… I’ve been looking for this since a week. Thanks a lot Kevin!

        1. Well glad to see you found wpsnipp, lots of wordpress snippets almost anything you can think of.

          1. Wrestling Network August 9, 2014 at 11:35 pm

            Can you disable this function on the register page?

          2. Not sure if I understand what exactly you are looking for, can you provide more details?

          3. Wrestling Network August 10, 2014 at 12:05 am

            The function works on the register page and i only want it to work on the login page.

          4. Wrestling Network August 10, 2014 at 12:07 am

            the register page is 2 fields “Username/Email” and “Email” and it’s really complicated for users to register.

  10. cool tip,works like a charm

    1. Perfect glad to see I could help!

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!