Allow Users to Login with Email Address in WordPress

By Default, WordPress doesn’t allow users to login with email address to the dashboard. However, you can easily fix this problem by adding a small amount of code to your functions.php file.

Must Read : How to Add Login & Logout Links to Your WordPress Menu

To enable login with email address use the following code,

add_filter('authenticate', 'ccw_allow_email_login', 20, 3);
function ccw_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 );
}

To replace Username text Username / Email address, place the following code in your functions.php file.

add_filter( 'gettext', 'ccw_addEmailToLogin', 20, 3 );
function ccw_addEmailToLogin( $translated_text, $text, $domain ) {
	if ( "Username" == $translated_text )
		$translated_text = __( 'Username / Email');
	return $translated_text;
}
Login With Email Address in WordPress

Login With Email Address in WordPress

0 Comments

Leave a Comment.