javascript - how to refresh page after user logout with 'wp_logout_url'?

admin2025-01-07  3

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.

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.

Share Improve this question edited Dec 23, 2016 at 11:34 Prasad Patel asked Dec 23, 2016 at 10:52 Prasad PatelPrasad Patel 1715 silver badges14 bronze badges 1
  • 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 Commented Dec 23, 2016 at 11:02
Add a comment  | 

2 Answers 2

Reset to default 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();
}

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>
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736259815a617.html

最新回复(0)