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>