Wordpress - How to disable autocomplete on the wp-login.php page

Your only solution (without modifying core files) is to use JavaScript.

function wpse_159462_login_form() {
    echo <<<html
<script>
    document.getElementById( "user_pass" ).autocomplete = "off";
</script>
html;
}

add_action( 'login_form', 'wpse_159462_login_form' );

Having said that, if you're not the only one that will be signing in I would advise against disabling autocomplete, it will almost certainly **** people off.


Here is a solution with PHP only I come up with:

function disable_autofill_password($safe_text, $text) {
    if($safe_text === 'user_pass') {
        $safe_text .= '" autocomplete="new-password';
    }
    return $safe_text;
}
add_filter('attribute_escape', 'disable_autofill_password', 10, 2);

It's a little hack of the esc_attr filter, it close the id attribute of the password input then add the autocomplete attribute (the new-password value is used for Chrome).