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.com/blog/2
I want to change the URL to: domain.com/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.