Codeable info

How To Login To WordPress Using Your Email Address

Posted on by in WordPress Tutorials

In order to login to your WordPress website a user must know their username and password. If a user can’t remember their password they can request a new password using their name or their email address. Many users use the same email address whenever they register with a website so there’s a good chance that a user will forget their username but know the email address. Unfortunately, WordPress doesn’t let users sign in with their email address so users who have forgotten their username will have to reset their password.

Bavotasan posted a great little tip a few weeks ago that addresses this issue and lets you log in to WordPress using the account email address. All you have to do is add the following function to your theme functions.php file:

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');

If you don’t like editing your theme templates, or would like this functionality throughout all of your website themes, you should install the WP Email Login. I’ve tried the manual solution and the WordPress plugin and they both work great.

The one drawback to this is that your members will not know that they can sign in using their email address as both of the above solutions do not change the login box i.e. it still says ‘Username’. What I recommend doing is changing this to ‘Username or Email Address’ (or something to that effect).

Edit The The WordPress Login Box

The easiest way to do this is to quickly edit your wp-login.php file (located at www.yoursite.com/wp-login.php). Simply look for the following piece of code:

<p>
		<label for="user_login"><?php _e('Username') ?><br />
		<input type="text" name="log" id="user_login" class="input" value="<?php echo esc_attr($user_login); ?>" size="20" tabindex="10" /></label>
	</p>
	<p>
		<label for="user_pass"><?php _e('Password') ?><br />
		<input type="password" name="pwd" id="user_pass" class="input" value="" size="20" tabindex="20" /></label>
	</p>

And change ‘Username’ to ‘Username or Email Address':

<p>
		<label for="user_login"><?php _e('Username or Email Address') ?><br />
		<input type="text" name="log" id="user_login" class="input" value="<?php echo esc_attr($user_login); ?>" size="20" tabindex="10" /></label>
	</p>
	<p>
		<label for="user_pass"><?php _e('Password') ?><br />
		<input type="password" name="pwd" id="user_pass" class="input" value="" size="20" tabindex="20" /></label>
	</p>

Admittedly, this isn’t an idea solution as any edits to wp-login.php will be over written whenever you update WordPress; however it only takes two seconds to change the template. It’s also kind of pointless adding the option of signing in using the account email address if members don’t even know they can.

Good luck,
Kevin

)
Codeable info

Comments (1)

Comment by Nino Blasco says:

Really liked it. Thank you.

Codeable info