skip to Main Content

WordPress Code Snippets


How to Auto Logout Inactive Users in WordPress

Learn how to use a simple script to ensure users are logged out after a period of inactivity, protecting your site from unauthorized access.

<script type="text/javascript">
	var logoutUrl = '<?php echo htmlspecialchars_decode( wp_logout_url() ); ?>';
	var timeout;
	document.onload = resetTimeout;
	document.onmousemove = resetTimeout;
	document.onkeypress = resetTimeout;
	function resetTimeout() {
		clearTimeout( timeout );
		timeout = setTimeout( function () {
			window.location.href = logoutUrl;
		}, 600000 ); // 10 minutes
	}
</script>

I’m a WordPress developer with 10+ years of experience in WooCommerce and custom plugins. I combine technical expertise with design flair to help you create standout, user-friendly websites. Let’s transform your digital presence!

Best WordPress Hosting
Back To Top