Skip to main content
5 of 5
added 35 characters in body

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?

I tried the one below but din't work either:

<script>
   window.onhashchange = function() {
       <?php if( ! is_user_logged_in()) { $this->tewa_login(); } ?>
   }
<script>

what's wrong plz can anyone tell me!