The login_form_defaults hook does work, but wp-login.php does not use wp_login_form() which runs the login_form_defaults hook, and instead the “Remember Me” checkbox is echoed like this, hence it’s basically unremovable via PHP or there’s no filter to disable (or an argument to bypass) the echo, or empty/modify the markup.
So that means, if wp_login_form() was used, then your code would have worked.
But on the wp-login.php page, you can disable the “Remember Me” via either CSS or JS, or both:
-
Use CSS to visually hide the checkbox, e.g. using the
login_headhook:add_action( 'login_head', function () { echo '<style>.forgetmenot { display: none !important }</style>'; } ); -
Use JS to completely remove the element, e.g. using the
login_footerhook:add_action( 'login_footer', function () { ?> <script> try { document.querySelector( '.forgetmenot' ).remove(); } catch ( err ) {} </script> <?php } );
Or just create a custom login page and send users to that page instead when they attempt to login.
That way, you can manually call wp_login_form() and just disable the “Remember Me” as you wish.