WordPress Disable Ability To Login With Email Address
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