1

Currently my pagination works like

http://example.com/city/usa/                     #for page 1
http://example.com/city/usa/page/2
http://example.com/city/usa/page/3    ...and so on

I want to change it to:

http://example.com/city/usa/                         #for page 1
http://example.com/city/usa/page2
http://example.com/city/usa/page3

I am using wp-pagenavi plugin.

What I have tried:
option1
option2
option3

What is the issue: If I access URL with .../page5 (or any page) then it redirects to .../page/5/

1

After searching here and there, probably I found solution. (Don't know if I am doing wrong in WP terminology!)

Page was redirecting from .../page5 to .../page/5, because of redirect_canonical function resides in Wordpress core.

So I further searched for altering it by hook.

Few people were saying remove redirect_canonical filter by adding this in code: remove_filter('template_redirect','redirect_canonical');.

But, after checking some other answers, I think I have to correct only my case, as removing whole redirect_canonical filter cause trouble in other part of Wordpress.


Here is my final code which was added in my theme's functions.php

function remove_page_number_permalink_redirect( $redirect_url )
{
    if (is_paged() && get_query_var('paged') > 0) {
        return false;
    }
    return $redirect_url;
}
add_filter( 'redirect_canonical', 'remove_page_number_permalink_redirect' );

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.