0

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". Iam trying the below code but it doesn't work.

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

My logout code is below:

if ( is_user_logged_in() ) {
  $data .= '<li><a class="add-new" href="'. wp_logout_url() .'" class="btn btn-primary" >'.$this->icon_sign_out.' Logout</a></li>';
}

Can the below code works or not?

function my_redirect(){
  <script>
     location.reload();
  </script>
 exit();
}
add_filter('wp_logout','my_redirect');

I think this issue totally browser issue not belongs to server. I think just a page refresh that does the trick. I was using 'wp_logout_url' for user logout. how to do it can anyone plz tell me? Thanks in advance.

bumped to the homepage by Community 2 days ago

This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.

  • Take time to edit your post for clarity of expression. As it stands, it is not clear what the challenge is, what you are trying to achieve, WordPress version, edited file and or location of custom code, any eventual error, etc. – nyedidikeke Dec 23 '16 at 11:02
0

Try using wp_redirect after logout. There's an example of how to use it here.

add_action( 'wp_logout', 'auto_redirect_external_after_logout');
function auto_redirect_external_after_logout(){
  wp_redirect( 'http://redirect-url' );
  exit();
}
  • Thanks for the quick reply. Could you please tell me where to write that 'wp_redirect'? I think may in theme functions.php file as a hook. – Prasad Patel Dec 23 '16 at 11:17
  • Just a link is not very good answer; could you please elaborate a practical answer with sample code and explain how it fix the problem of the question? – cybmeta Dec 23 '16 at 11:41
  • I just have edited it. – dgarceran Dec 23 '16 at 11:42
0

if you want to refresh (and not redirect to a different page) use 'get_permalink()'

it's in the docs...

<a href="<?php echo wp_logout_url( get_permalink() ); ?>">Logout</a>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.