Turn Off Autofocus on the Login Form
Stops the login, lost password and registration screens from putting the cursor in the first field as soon as they load, so the page does not jump or pop up the on-screen keyboard.
Opens WPIDE on
Code
// The main login form has a filter for this.
add_filter( 'enable_login_autofocus', '__return_false' );
// The lost password, registration and reset password forms focus their first field without a filter,
// so take the focus away again right after WordPress sets it.
add_action( 'login_footer', function () {
wp_print_inline_script_tag( '(function(){var field=document.activeElement;if(field&&field!==document.body&&field.form){field.blur();}})();' );
} );
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.