How to Login to WordPress using Email Address

Most Website’s allow users to login using their email ID & we all know In general WordPress  only allows you to login using username.What if the case an user of your WordPress website registers with thousands of other website’s & have different usernames at each of them.

The Scenario would be something like this each time the user come backs to your site he or she needs to request for their forgotten username.

The Solution would be Allow your users to login using their email ID too.

In this post we will go through the available options which enables your users to login using their email address too.

How to Login to WordPress using Email Address

Methods to enable WordPress login using Email Address :

Below are the Two methods by which you can enable your WordPress users to login using their email Id as username.

1. Using a Code Snippet

Copy the below piece of code written by Bavotsan into your WordPress themes functions.php file

function email_address_login($username) {
$user = get_user_by_email($username);
if(!empty($user->user_login))
$username = $user->user_login;
return $username;
}
add_action('wp_authenticate','email_address_login');

This code will enable users to sign into your WordPress site using an email address or by default, the username.

But this doesn’t make your user’s to recognize that they will be able to login using email ID, to achieve that we need to modify wp-login.php file which is located under your website’s root folder & can be accessed by www.yourwebsite.com/wp-login.php.

Loginto your website root folder using some FTP software & download the file wp-login.php & search for this line of code.

<p>
<label for=”user_login”><?php _e(‘Username’) ?><br />
<input type=”text” name=”user_login” id=”user_login” value=”<?php echo esc_attr(stripslashes($user_login)); ?>” size=”20″ tabindex=”10″ /></label>
</p>

Now replace the above line of code with the below

<p>
<label for=”user_login”><?php _e(‘Username or E-mail ID’) ?><br />
<input type=”text” name=”user_login” id=”user_login” value=”<?php echo esc_attr(stripslashes($user_login)); ?>” size=”20″ tabindex=”10″ /></label>
</p>

But remember this code gets replaced when ever you update your version of WordPress to some new version, so Bookmark this page for future reference.

2. Using WP Email Login plugin

If you feel the above option is tricky & fear of editing the files then just download,install & Activate WP Email Login plugin.

 WordPress Plugin Download Link

Hope you like this tutorial, Please do share your views & let us know if you know any other option that would do the job better.