Disable Login Field Autofocus
Removes the automatic focus on the username input at wp-login.php to prevent browsers from surfacing stored credentials unsolicited.
PHPby SnipCraft
php
<?php
/**
* Removes the auto-focus behavior on the username field at wp-login.php.
* Prevents browsers from automatically highlighting and populating the
* credential field before the user interacts with the page.
*/
if ( ! function_exists( 'scseed_disable_login_autofocus' ) ) {
function scseed_disable_login_autofocus() {
?>
<script>
document.addEventListener('DOMContentLoaded', function() {
var field = document.getElementById('user_login');
if (!field) { return; }
field.removeAttribute('autofocus');
if (document.activeElement === field) {
field.blur();
}
});
</script>
<?php
}
add_action( 'login_head', 'scseed_disable_login_autofocus' );
}#autofocus#hardening#login#privacy#security