To ensure that your pagination URLs reflect the slug "pagina" instead of "page," the changes in the post_pagination function alone are not sufficient. You'll need to modify the permalink structure in your WordPress configuration. Here's a comprehensive approach to changing the pagination slug:
Step 1: Update Your post_pagination Function
Based on your previous function, ensure you are using the correct pagination slug. The earlier updates mentioned should be in place. Here is the refined version:
function post_pagination($paged = '', $max_page = '') {
if (!$paged) {
$paged = get_query_var('paged') ? get_query_var('paged') : 1; // Use 'paged' instead of 'page'
}
if (!$max_page) {
global $wp_query;
$max_page = isset($wp_query->max_num_pages) ? $wp_query->max_num_pages : 1;
}
$big = 999999999; // need an unlikely integer
$html = paginate_links(array(
'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
'format' => 'pagina/%#%', // Update to use "pagina"
'current' => max(1, $paged),
'total' => $max_page,
'mid_size' => 1,
'prev_text' => __('<i class="rs-pagination-chevron fa-solid fa-chevron-left rs-text-primary small"></i> Anterior'),
'next_text' => __('Siguiente <i class="rs-pagination-chevron fa-solid fa-chevron-right rs-text-primary small"></i>'),
));
$html = "<div class='navigation pagination'>" . $html . "</div>";
echo $html;
}
Step 2: Change the Pagination Base in WordPress
Now, WordPress needs to understand that the base for pagination has changed from "page" to "pagina." This requires adjusting the rewrite rules and possible rewriting of get_pagenum_link().
-
Add a Filter to Change the Pagination Base:
You can use the paginate_links to change the default pagination base. To fully customize the pagination handling, you'll want to add a filter to your functions.php:
add_filter('request', function($query_vars) {
if (isset($query_vars['pagina'])) {
$query_vars['paged'] = $query_vars['pagina'];
unset($query_vars['pagina']);
}
return $query_vars;
});
add_filter('paginate_links', function($link) {
return str_replace('/page/', '/pagina/', $link);
});
-
Rewrite Rules:
If you want to update the permalink structure, add the following to your functions.php:
add_action('init', function() {
add_rewrite_rule('^pagina/([0-9]+)/?$', 'index.php?pagename=your-blog-page-name&paged=$matches[1]', 'top');
});
Replace your-blog-page-name with the actual slug of the page where your posts are listed.
Step 3: Flush Rewrite Rules
After making these changes, you must flush the rewrite rules:
- Go to Settings > Permalinks in the WordPress dashboard.
- Simply click "Save Changes" without altering anything.
This will regenerate the rewrite rules based on your new settings.
Step 4: Test the URLs
Now check your pagination links:
- Visit
https://test.com/pagina/2
- Ensure the pagination works as expected.
Troubleshooting
If you still see "page" instead of "pagina," consider these:
-
Caching: Clear any caches from caching plugins (like W3 Total Cache, WP Super Cache, etc.) or server-side caching, if enabled.
-
Conflicting Plugins: Deactivate other plugins that may modify URL structures or pagination, then test again.
-
Default Theme: Temporarily switch to a default theme (like Twenty Twenty-One) to see if the theme's functions are causing conflicts.
-
Manual Browser Cache: Ensure your browser cache is cleared since changes might not appear immediately due to caching.
If you follow all these steps and still experience issues, please let me know, and we can explore further troubleshooting options.