The usual way to login to WordPress is with a username and password. However, there are times where it is more preferable to login with an email address. In this tutorial, we will show you how you can add a “login with email address” field in the login form.
The “Login with Email Address” feature is the same as the normal login, except that we will add an extra check for email address during the authentication process. For this, we will hook up to the authentication filter and check if the email address exists in the database.
functions.php file and paste the following code:
What this function does is to first check whether the username input field is an email, and if yes, then retrieve the user from the database based on the email address. If the retrieval is successful, grab its username and use it together with the password to authenticate the login.
Replacing the “username” text
Now that we have enabled the user to login by email address, we have to change the login text from “Username” to Username/Email” so users know that they can login with their email address. This is how we do it:
Copy and paste the following code to your
And this is how it looks like: