Users & Login PHP Beginner

Tick “Remember Me” by Default

Pre-tick the "Remember Me" box on the login form so users stay logged in for two weeks instead of until they close the browser.

Tested on WordPress 7.1 PHP 8.3 No plugin needed Updated
functions.php 12 lines
add_action( 'login_footer', function (): void {
	?>
	<script>
		( function () {
			var box = document.getElementById( 'rememberme' );
			if ( box ) {
				box.checked = true;
			}
		} )();
	</script>
	<?php
} );

Where to add this

Recommended A code snippets plugin Survives theme changes and is easy to switch off.
Child theme At the end of your child theme's functions.php file.
Must-use plugin As a .php file in wp-content/mu-plugins, starting with <?php.

Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.

Without “Remember Me”, WordPress logs users out when they close their browser. On sites where people log in often, like membership sites or stores, that’s annoying. This snippet ticks the box for them.

How it works

login_footer runs at the bottom of the login page. The small script finds the checkbox with the ID rememberme and ticks it. Users can still untick it on a shared computer.

Things to watch

  • Remembered logins last 14 days by default. To change that, see “Shorten Login Sessions”.
  • This only affects the standard wp-login.php form, not custom login forms.

How to test it

Log out and open the login page. The “Remember Me” box should already be ticked.

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only