admin管理员组

文章数量:1323330

My posts pagination in not working in WordPress 5.5 and So, I want to rewrite the URL for the pagination. I am using posts with pagination in the inner page with slug "post".

Current URL (The Pagination): domain/blog/2

I want to change the URL to: domain/blog/page/2

By changing the URL, the posts pagination start working. I added the jQuery code and the pagination is working but how I can do that in WordPress.

My code added in functions.php:

function my_pagination_rewrite() {
    add_rewrite_rule('blog/page/?([0-9]{1,})/?$', 'index.php?page=blog&paged=$matches[1]', 'top');
}
add_action('init', 'my_pagination_rewrite');

But this is not working.

I also tried the code using jQuery and it is working:

<script>
    jQuery('.elementor-pagination').find('a').each(function() {
    
    var url=jQuery(this).attr('href');
    var pieces = url.split("/");
    
    var newhrf =window.location.origin+'/blog/page/'+pieces[4];
    jQuery(this).attr('href',newhrf);
});
</script>

The jQuery code ia working but my code in functions.php is not working.

Any help is much appreciated.

My posts pagination in not working in WordPress 5.5 and So, I want to rewrite the URL for the pagination. I am using posts with pagination in the inner page with slug "post".

Current URL (The Pagination): domain/blog/2

I want to change the URL to: domain/blog/page/2

By changing the URL, the posts pagination start working. I added the jQuery code and the pagination is working but how I can do that in WordPress.

My code added in functions.php:

function my_pagination_rewrite() {
    add_rewrite_rule('blog/page/?([0-9]{1,})/?$', 'index.php?page=blog&paged=$matches[1]', 'top');
}
add_action('init', 'my_pagination_rewrite');

But this is not working.

I also tried the code using jQuery and it is working:

<script>
    jQuery('.elementor-pagination').find('a').each(function() {
    
    var url=jQuery(this).attr('href');
    var pieces = url.split("/");
    
    var newhrf =window.location.origin+'/blog/page/'+pieces[4];
    jQuery(this).attr('href',newhrf);
});
</script>

The jQuery code ia working but my code in functions.php is not working.

Any help is much appreciated.

Share Improve this question edited Sep 2, 2020 at 19:33 Rahul Kumar asked Aug 18, 2020 at 19:42 Rahul KumarRahul Kumar 2074 silver badges20 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Seems to be related to: WordPress stripping out "page" query parameter with 301 redirect.

See Make WordPress Core ticket 50976:

"We understand that it may be annoying for themes and plugins authors to fix their usage of this variable, but it would introduce a way more issues if it was changed on WordPress Core side. It's objectively better to get this fixed on plugins and themes since it is a wrong usage of WordPress variables.

Closing this as wontfix, as the issue shouldn't be fixed on WordPress core but rather on plugins and themes side."

本文标签: url rewritingNot able to rewrite the pagination URL for the posts