Login with email address or username

WordPress Business Themes Forums Plugins – Share & Recommend WordPress Plugins Login with email address or username

Login with email address or username

July 4, 2013
Shakib Shakib
  • Shakib
    Shakib
    Newbie 41 points

    Hi,
    Adding below code to your _functions.php will enable your users to login with their email address or username. At the moment one can login only with username.

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

    • This topic was modified 5 years, 11 months ago by Mark Fail Mark Fail.
    July 4, 2013 at 5:13 pm
  • David Harris
    David Harris
    Senior Member 367 points

    Nice Shakib. +1

    July 5, 2013 at 5:04 am
  • Mark Fail
    Mark Fail
    Super Guru 12,812 points

    thanks for sharing :)

    July 5, 2013 at 8:47 am
  • Narender Kumar
    Narender Kumar
    Senior Member 273 points

    Can I place it in custom styles box.

    July 8, 2013 at 5:40 pm
  • Shakib
    Shakib
    Newbie 41 points

    Hi,
    No this must go in your _functions.php file in your themes folder. If you don’t have _functions.php file then see attached.
    Copy the file to your theme directory, see example below:

    wp-content\themes\directorypress\themes\directorypress-Glow-Directory\_functions.php

    btw, custom styles box is for css

    Attachments:
    You must be logged in to view attached files.
    July 8, 2013 at 6:03 pm
  • Narender Kumar
    Narender Kumar
    Senior Member 273 points

    Thanks a lot . Iam still in the learning mode ( self Taught). 😀

    July 8, 2013 at 6:16 pm

  • Alexandra
    Newbie 65 points

    so can you login with both username or email ?
    or can you only login with email after adding that function ?

    July 18, 2013 at 4:39 am
  • Mark Fail
    Mark Fail
    Super Guru 12,812 points

    try your own site, see which you can do as it seems to be a mixture.

    July 18, 2013 at 5:15 am
  • CTK
    CTK
    Newbie 26 points

    AWESOME!!! I was looking for a feature like this for our site!!! YEAHHH!!!!

    July 21, 2013 at 10:15 pm
  • Mark Fail
    Mark Fail
    Super Guru 12,812 points

    :)

    July 22, 2013 at 1:03 am
  • Declan
    Declan
    Newbie 41 points

    would this be a different file for coupon responsive?

    July 22, 2013 at 3:36 pm

  • Bhadmus Francis
    Newbie 4 points

    please be specific about the exact _function file to edit

    August 1, 2013 at 10:28 am
  • CTK
    CTK
    Newbie 26 points

    I’m not getting it to work – here’s what I put in to my _functions.php:

    /***LOGIN WITH EMAIL****/

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

    ?>

    Is it possible that there’s some variables conflicting? Just looking above, I see plenty of $user variables popping up.

    August 4, 2013 at 9:08 pm
  • Jennifer
    Jennifer
    Senior Member 119 points

    This isn’t working for me. I can’t find any syntax errors and tried another similar code block on a WP forum that also didn’t word. Is there a theme conflict? Any suggestions? And along with that, where is the file that allows us to change the text from “username” to “username or email” above the login box? Thanks, Jennifer

    February 16, 2014 at 3:20 am
  • Mohamed
    Mohamed
    Newbie 24 points

    Hi Jennifer,

    Instal this plugin:

    http://wordpress.org/plugins/wp-email-login/

    #Worksforme #classifieds

    March 3, 2014 at 12:38 pm
Viewing 15 posts - 1 through 15 (of 17 total)

Didn't find what you were after?

Chat with us now

or contact our support team