WordPress Disable Ability To Login With Email Address


About The Author
Cabe Nolan is the founder of WP Cover where he shares his insight into WordPress, development, & entrepreneurship. Outside of WPCover, Cabe continues to run a successful WordPress development firm, Bold City Design as well as a few high profile websites, Arrivala, Two Way Resume, Dock Skipper, and a successful outdoors brand, DolfinPack.







WordPress Disable Ability To Login With Email Address

With the release of WordPress version 4.5, came the default functionality of allowing users to login with their email address or username. For most, this was a feature that was much requested and a blessing. For some, they believe email addresses are more common knowledge than a username and were looking to disable the functionality for added security, so here you go:

CubeColour quickly released a plugin that handled this request very simply and elegantly which is available from the repository here. If you’re like me and prefer to keep your plugins limited, I’ve broken the plugin into a simple function that you can copy and paste into your active themes function.php file to handle the change. The first half of the below snippet handles the change on the frontend wp-login.php screen changing ‘Username or Email’ to ‘Username’. The very last line of the function is what actually handles the removal of the authentication by email.

function cc_login_username_label() {
	add_filter( 'gettext', 'cc_login_username_label_change', 20, 3 );

	function cc_login_username_label_change( $translated_text, $text, $domain )  {
		if ($text === 'Username or Email') {
			$translated_text = __( 'Username' ); // Use WordPress's own translation of 'Username'
		}
		return $translated_text;
	}
}

add_action( 'login_head', 'cc_login_username_label' );

function cc_change_login_username_label( $defaults ){
    $defaults['label_username'] = __( 'Username' );
    return $defaults;
}

add_filter( 'login_form_defaults', 'cc_change_login_username_label' );

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

That’s all folks!


Share Your Thoughts

Leave a Reply

Your email address will not be published.


Related Stuff You Might Like







WordPress News, Tips, & Code Snippets

Join the WP Cover mailing list and get wordpress news, tips, code snippets, security warnings, and more delivered right to your inbox.  We won't flood your inbox, newsletters typically go out every 1-2 weeks unless it involves an important security release.

You have Successfully Subscribed!