Skip to content

Instantly share code, notes, and snippets.

@dknauss
Last active January 6, 2025 19:22
Show Gist options
  • Select an option

  • Save dknauss/fdd1d74304b278edcffc36c186fe9632 to your computer and use it in GitHub Desktop.

Select an option

Save dknauss/fdd1d74304b278edcffc36c186fe9632 to your computer and use it in GitHub Desktop.
Expire Idle WordPress Sessions (JavaScript)
<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>
// Note: This cannot be considered a secure method because the client can always see and manipulate the code in the DOM.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment