How to allow users to login through email or username in WordPress

22 Jul

How to allow users to login through email or username in WordPress

Context: Very often you want to allow user to login using email or username.

Solution: Adding action hook, ‘wp_authenticate’ we can allow users to login using email address or username.

<!--?php function login_using_email_or_username($username) { $usern = get_user_by('email',$username); if(!empty($usern-&gt;user_login))&lt;br ?--> $username = $usern-&gt;user_login;
return $username;
}
add_action('wp_authenticate','login_using_email_or_username');

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

Bydr.code.skm

I am backend developer with passion in Web Application development using latest technologies like Laravel, PHP7, React, ECMAScript 6 and WordPress. I prefer spending time analyzing big data with Apache Spark. Apart from that, I do photography.