Allow users to register and login to your WordPress site using e-mail

More and more WordPress users want their members to be able to register and login to the site by using e-mail address instead of a simple username which WP provides. By doing this, you can help your users remember their login details easier; if you’re having many members, there are chances many usernames will be already taken and your new members will have to choose ones they don’t usually use.

Like working with almost anything else in WordPress, you can do this by using two different methods – you can manually insert a code into core files or create a site specific plugin or you can find a plugin which will do the dirty work for you.

Even if you’re new to WordPress, you can easily implement both techniques. But, since the first one requires you to manually edit a WP core file, if you’re not completely sure you can handle it, skip to the other technique and install the plugin.

Use the code:

  1. Open functions.php file
  2. Copy and paste the following code
  3. add_action( ‘wp_authenticate’, ’email_address_login’ );

    function email_address_login( &$username, &$password )
    {
    $user = get_user_by( ’email’, $username );

    if( !empty( $user->user_login ) )
    {
    $username = $user->user_login;
    }
    }

  4. Now you have to let users know they can login with e-mail. There are different solution for this, but let’s go with the simplest one. If you remember your login form, you are always asked for “Username” and “Password”, so you can simply change the label in the form. To do that, you will need the following code which you have to paste in the same functions.php file as the code from the previous step:
add_filter( 'gettext', 'addEmailToLogin', 20, 3 );

function addEmailToLogin( $translated_text, $text, $domain ) {
if ( "Username" == $translated_text )
$translated_text .= __( ' or use e-mail');
return $translated_text;
}

That’s it. Now you should logout and log back in with your email to see if everything’s working ok.

Using the plugin:

If you want to do the same thing without having to mess with the code, you can use a simple WP email login plugin. This one can be found for free in the WordPress plugin repository. The process of activating email login is very simple:

  1. Go to Plugins->Add New
  2. Search for “WP Email Login” plugin
  3. Install and activate it
  4. Logout
  5. Login by using your email address instead your WP username

START YOUR OWN BLOG

This guide is an introduction to mastering the art of blogging. It provides easy to follow steps to start, maintain, and grow your blog.

Read the guide

Leave a Reply

Your email address will not be published. Required fields are marked *