Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

how to logout user on browser tab or window closes

I worked long on this one. It is because of the WordPress remember me. Use this code in your theme’s functions.php and it should fix your issue:

function myplugin_cookie_expiration( $expiration, $user_id, $remember ) {
    return $remember ? $expiration : 180;
}
add_filter( 'auth_cookie_expiration', 'myplugin_cookie_expiration', 99, 3 );

Related Posts:

  1. How reduce wordpress login session timeout time?
  2. Custom Connect to Facebook, problem logging in/logging out
  3. Session Experies and Get Logged Out Within Few Minutes
  4. Preventing session timeout
  5. Removing username from the ‘wordpress_logged_in’ cookie
  6. Disable WordPress 3.6 idle logout / login modal window / session expiration
  7. How to pass users back and forth using session data?
  8. How to fake a WordPress login?
  9. Does wp_logout_url() destroy a session? (Logging out question)
  10. share login/logout sessions across two installs?
  11. How can I test the login for an expired session?
  12. How do I extend auto logout on idle OR redirect inline popup
  13. How long do users stay logged in if they DON’T check remember me?
  14. How to get login data (session) outside WordPress?
  15. How can I test the login for an expired session?
  16. How does WordPress handle sessions?
  17. Preexisting login to change to logout link in sub menu
  18. WordPress as webapp login session
  19. Share WordPress login info with other PHP app
  20. WordPress error on log out ‘Not Permitted’ and can’t log out
  21. Add logout link when logged in, make it disappear when logged out?
  22. Lock out all WordPress Administrators except two specific users
  23. How to remove ‘wordpress…’ text from page titles in tabs
  24. One time login on 2 different WordPress sites
  25. add class to element if user is not logged in [closed]
  26. End session screen not close automatically after login
  27. Problem with is_user_logged_in() function in some pages
  28. wordpress login loop and session problem
  29. Get WordPress logged in username from root domain when WP is installed in a subfolder
  30. Why deleting/removing cookies in WordPress does not log me out from admin?
  31. User not logged first time I open the homepage
  32. wp_logout logging everyone out instead of just the user that clicked the logout link!
  33. How to limit user to login only once per session
  34. how to manage Session in WordPress using custom login?
  35. Inconsistent login state
  36. Can i hide a dynamically created div to logged out users?
  37. In Django, how do I know the currently logged-in user?
  38. Can I programmatically login a user without a password?
  39. Can’t log in: “ERROR: Cookies are blocked or not supported by your browser. You must enable cookies to use WordPress.”
  40. Is there any way to rename or hide wp-login.php?
  41. How to login with email only no username?
  42. How can I redirect user after entering wrong password?
  43. Increase of failed login attempts, brute force attacks? [closed]
  44. Login page ERROR: Cookies are blocked due to unexpected output
  45. Separate registration and login for different roles
  46. SSO / authentication integration with external ‘directory service’
  47. How to prefill WordPress registration with social details
  48. Check for correct username on custom login form
  49. Disallow user from editing their own profile information
  50. I can’t access my site via wp-admin
  51. ‘Password field is empty’ error when using autofill in Chrome
  52. How to show ‘login error’ and ‘lost password’ on my template page?
  53. What is $interim_login?
  54. Custom login form
  55. How to prefill the username/password fields on the login page
  56. wp_signon returns user, but the user is not logged in
  57. Adding extra authentication field in login page
  58. Destroy user sessions based on user ID
  59. Prevent wp_login_form() from redirecting to wp-admin when there are errors
  60. Redirect user using the ‘wp_login_failed’ action hook if the error is ’empty_username’ or ’empty_password’
  61. wp_signon() does not authenticate user guidance needed
  62. What exactly is ReAuth?
  63. What are the differences between wp_users and wp_usermeta tables?
  64. Login members using web services
  65. Make my wordpress blog remember my login “forever”
  66. How to check in timber if user is loggedin?
  67. How do I change the language of only the login page?
  68. How to change the default logout link on WordPress Admin
  69. Stop WordPress from logging me out (need to keep me logged in)
  70. Woocommerce registration page [closed]
  71. How to disable autocomplete on the wp-login.php page
  72. Share login data/cookies between multiple installations
  73. Synchronize WordPress user accounts across multiple domains and installations without using WordPress MU
  74. How do I change the logo on the login page?
  75. Allow up to 5 Concurrent Login Sessions
  76. Why does WordPress hide the reset password key from the URL?
  77. Is it possible to sign in with user_email in WordPress?
  78. How to use current_user_can()?
  79. Avoid to load default WP styles in login screen
  80. WordPress registration message
  81. how to display the wordpress login and register forms on a page?
  82. How can I send a welcome email to a user AFTER they login for the first time?
  83. Can not login with correct username and password
  84. Website Visible only to Registered users
  85. How can i increase the login expiration length?
  86. How do I use add_action from a class method?
  87. How to remove the WordPress logo from login and register page?
  88. How can I add a custom script to footer of login page?
  89. Brute force attack?
  90. Customize wp_new_user_notification_email()
  91. Need to execute a cron job
  92. Masking logout URL
  93. Login email after registration never sent or received
  94. How can I create a separate blog that is private?
  95. How to keep always logged in development environment
  96. Add Confirm Password field in wp-login.php Password Reset page
  97. handling login/logout redirects
  98. Integrate recaptcha and wp_signon – what is needed?
  99. Stop users from logging in from multiple locations
  100. Clearing cookie on logout and session expiration
Categories login Tags login, logout, session
How to control the order of the combination of enqueued styles and scripts – site speed issue
Custom query form submission pagination

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress