If you use customized permalinks such as /%category%/%postname%/
you may receive a 404 error when trying to access your WordPress page, https://yoursite.com/page/2/
and so on.

This is an error that has been occurring since WordPress 2.7, and even today it happens more than reasonable when accessing the web page, no matter what theme you have.
This happens more than I thought but, like everything in WordPress, it has one or several possible solutions.
Table of Contents
Change the permalinks
The first solution is obvious, to change the structure of permalinks.
Go to your WordPress desktop and under Settings > Permalinks
, change the current custom structure to “postname
“.
I understand that you may not always be able to make this change, mainly due to SEO issues, but I recommend you at least to try it.
Change the structure as I say and try to see if the pagination works. Then, if you can make the perfect permalink change, you can keep this structure and make the 301 or regex redirects that are necessary to not lose positioning.
Delete .htaccess
Also, on occasion, permanent links may not be properly written from the server. To check this, nothing is easier than deleting the current .htaccess file (it will be in the root folder where WordPress is installed).
Then go to the WordPress desktop, to Settings > Permalinks
, and save changes without touching any settings.
Use a function that corrects the paging error
If none of the above works, or you can’t apply it, the following code will fix the problem in 99% of the cases.
function wphelp_custom_pre_get_posts( $query ) {
if( $query->is_main_query() && !$query->is_feed() && !is_admin() && is_category()) {
$query->set( 'paged', str_replace( '/', '', get_query_var( 'page' ) ) ); } }
add_action('pre_get_posts','wphelp_custom_pre_get_posts');
function wphelp_custom_request($query_string ) {
if( isset( $query_string['page'] ) ) {
if( ''!=$query_string['page'] ) {
if( isset( $query_string['name'] ) ) { unset( $query_string['name'] ); } } } return $query_string; }
add_filter('request', 'wphelp_custom_request');
Code language: PHP (php)
Add the code to the end of the functions.php file of the active theme or to your miscellaneous customizations plugin, save the changes and it will almost certainly be fixed.
Read this post in Spanish: Cómo arreglar el error 404 en la paginación con enlaces permanentes personalizados
Wow the code worked for me.. i modified default post type and custom permalink and my pagination kept throwing 404 error.. and the function solved it for me.. thank you so much.
You are welcome!
I paste this code in my function.php It solve the error but when I click on page 2 page change butt the post remains the same till the last page. how I can fix it.