How to Login using Email Address in WordPress

Default option allow ‘username’ only to login in WordPress. Allowing login using email is a general approach in most cases and here is a quick code snippet to allow login in WordPress using email address as well username:

[code]
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’);
[/code]

You can also change ‘username’ label in to ‘Username / Email’ using:

[code]
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’ );
[/code]

No change in core files is required and just by adding these in functions.php you can have provide more flexible login option to user.

Deepak Sihag

Deepak is a Technical consultant, working on web since last 12 years. He excels in Microsoft .Net, OpenSource (mainly WordPress customization & plugin development) as well love working with CRM. He has been working with startups to listed companies and help them to build their online presence and reach target audience.

More Posts - Twitter - LinkedIn