Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

1 Answer

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
add comment

Your Answer

 
discard

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.