Monday 7 October 2013

How To Login To WordPress Using Your Username Or Email Address

Important: All scripts hosted on widcraft.googlecode.com don't work anymore because Google has blocked that SVN repository.
By default, WordPress only allows us to login to WordPress powered sites only with our username. But most of us prefer to enter our email address to login because remembering your email is more simple than usernames.

C. Bavota from bavotasan.com found a great way to allow your users to use either their username or email address to log into WordPress without any plugin. Just add following code to your 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');

Kevin Chard improved this trick by adding a snippet to it, which will change the text on the login page from “username” to “username / email.” Add following snippet to your functions.php just below the first 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' );
Important: Check our new website TricksPanda.com for WordPress tutorials, plugins and more.
 
Powered by Blogger.