WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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>';  

share|improve this question
up vote 2 down vote accepted

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'] );
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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