简体   繁体   中英

Clear user session on closing browser in Wordpress

I want to clear the current session of a user on frontend in wordpress while closing the browser or tab. Currently when I login and close the browser, the user is already logged in.

I am using Wordpress 4.0 version. So please advise how I achieve this.

If you can include a JavaScript and know the exact wordpress cookie you can use following code to detect on close event and inside clear the cookie

window.onbeforeunload = function () {
       // Clear cookie here
      };

Why don't you use the wp_logout function? Destroys the active session.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM