Users & Login PHP Beginner

Let Users Log In With Email Only

Stop people logging in with a username, so only an email address and password work on the login form.

Tested on WordPress 7.1 PHP 8.3 No plugin needed Updated
functions.php 8 lines
remove_filter( 'authenticate', 'wp_authenticate_username_password', 20 );

add_filter( 'gettext', function ( string $translation, string $text, string $domain ): string {
	if ( 'default' === $domain && 'Username or Email Address' === $text ) {
		return 'Email Address';
	}
	return $translation;
}, 10, 3 );

Where to add this

Recommended A code snippets plugin Survives theme changes and is easy to switch off.
Child theme At the end of your child theme's functions.php file.
Must-use plugin As a .php file in wp-content/mu-plugins, starting with <?php.

Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.

Usernames are often easy to guess, and people forget which one they picked. Logging in with an email address is simpler for users and gives attackers one less thing to try. This snippet allows email logins only.

How it works

WordPress checks logins through the authenticate filter. Two checks are attached to it: one for usernames and one for email addresses. Removing wp_authenticate_username_password leaves only the email check.

The gettext filter changes the form label from “Username or Email Address” to “Email Address”, so people know what to type.

Things to watch

  • Tell your users before you add this. Anyone used to their username will get “Unknown email address”.
  • Application passwords and other login plugins may add their own checks to authenticate and aren’t affected.

How to test it

Log out, then try to log in with your username. It should fail. Logging in with your email should work.

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only