Allow user to login with email address

We can easily enable wordpress users to login using email id. To do this, we can use the hook “authenticate

Simply copy the following snippet in your plugin or functions.php file

add_filter('authenticate', 'allow_email_login', 20, 3);

function allow_email_login( $user, $username, $password ) 

{

 if ( is_email( $username ) ) {

  $user = get_user_by_email( $username );

if ( $user ) $username = $user->user_login;

 }
return wp_authenticate_username_password( null, $username, $password );

}