1

Following a Wordpress Pagination tutorial, wp_logout_url( get_permalink() ); no longer redirects to the correct page. Instead of redirecting to say domain.com/page/2/, it redirects me to one of the posts in the listed category.

Is there a way to fix this?

global $wp_query;  

$total_pages = $wp_query->max_num_pages;  

if ($total_pages > 1){  

  $current_page = max(1, get_query_var('paged'));  

  echo '<div class="page_nav">';  

  echo paginate_links(array(  
      'base' => get_pagenum_link(1) . '%_%',  
      'format' => 'page/%#%',  
      'current' => $current_page,  
      'total' => $total_pages,  
      'prev_text' => 'Prev',  
      'next_text' => 'Next'  
    ));  

  echo '</div>';  

}  

1 Answer 1

2

It's not clear, but I'm assuming you want a 'log out' url, that brings the user back to the current page?

get_permalink() however, get's the permalink of the current post in the loop (if you're using it outside the loop, you'll find that it takes the user to the last post in the loop after they log out).

To get the url of whatever page you're currently on, you can use $_SERVER['REQUEST_URI']; (if there is a WordPress function that does this, apart from using add_query_arg() I would like to know it...)

So try:

 wp_logout_url( $_SERVER['REQUEST_URI'] );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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