Skip to main content
3 of 5
edited title
cjbj
  • 15k
  • 16
  • 42
  • 89

Is there any way to check for user login and send him to login?

I have written a plugin for my own site where I have an issue like "after user login to the site if he logout then again if he clicks on browser back button then the previous page showing again instead of login page". for this issue I fixed it by using below js code:

history.pushState(null, null, document.URL);
window.addEventListener('popstate', function () {
 history.pushState(null, null, document.URL);
});

The browser back button issue fixed but after adding the above js code I got new issue i.e. browser back button totally getting disabled, what if user wants to use browser back button to navigate through the site web pages?

IS there any hook that I can write in theme functions.php file? so that I can fix this issue if user clicks on browser back button after logout? can anyone please tell me how to fix it?