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 badges1 Answer
Reset to default 1Seems 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
版权声明:本文标题:url rewriting - Not able to rewrite the pagination URL for the posts 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742141220a2422588.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论