Can you tell me a function to insert in the functions.php file to remove the login via username option?

I would like the user to be able to log in only with his registered email.

  • I assume you are looking for the filter authenticate: codex.wordpress.org/Plugin_API/Filter_Reference/authenticate – Matthew Brown aka Lord Matt Sep 16 '19 at 12:08
  • I think so, can you give me the exact code to allow users to access only via email and password? Without using the username? Thanks – Matteo Feduzi Sep 16 '19 at 12:57
  • 3
    Keep in mind that embedding this in the theme will mean on any theme change it'll be impossible to login as nobody would know their usernames. Put it in an mu-plugin or a normal plugin. It'll be just as fast, except now it'll work for all themes, and can be copied between sites easily. Putting functionality like this inside a theme is very bad practice, themes should only contain visuals/styles/templates – Tom J Nowell Sep 16 '19 at 13:17
  • Hi, @MatteoFeduzi, I'm glad I could help you progress towards a solution. You may not be aware but the community is not terribly fond of "write my code" questions seeing them as "do my homework for me". See this discussion for a more in-depth look at question and answer standards regarding code. – Matthew Brown aka Lord Matt Sep 16 '19 at 14:20

In default-filters you'll see

// Default authentication filters
add_filter( 'authenticate', 'wp_authenticate_username_password', 20, 3 );
add_filter( 'authenticate', 'wp_authenticate_email_password', 20, 3 );

so you just need to

remove_filter( 'authenticate', 'wp_authenticate_username_password', 20 );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.