WordPress /page/2 404 pagination issue
Today in this tutorial, I will solve the WordPress /page/2 404 pagination issue. /page/2 404 pagination issue is a permalink issue. So In this tutorial, I will give you an example of how to solve the WordPress /page/2 404 pagination issue.
WordPress /page/2 404 pagination issue
Example: 1 When you use the posts_per_page = 6
and WordPress default posts_per_page = 10
, So in this case, we put posts_per_page = 6
on Settings/Reading.
Example: 2 Replace parameter ‘page’ with ‘paged’.
#functions.php
function remove_page_from_url_string($arg)
{
if ($arg['name'] == 'page' && isset($arg['page'])) {
unset($arg['name']);
$arg['paged'] = $arg['page'];
}
return $arg;
}
add_filter('request', 'remove_page_from_url_string');
Example: 3 Rewrite Rule
#functions.php
function category_pagination_rewrite() {
add_rewrite_rule('bike/page/?([0-9]{1,})/?$', 'index.php?category_name=bike&paged=$matches[1]', 'top');
}
add_action('init', 'category_pagination_rewrite');
Replace bike
with your category name in the code above.
After adding this code, make sure you go to Settings > Permalinks and click Save.