The paginate_links_output WordPress PHP filter allows you to modify the HTML output of paginated links for archives.
Usage
add_filter('paginate_links_output', 'your_custom_function', 10, 2); function your_custom_function($r, $args) { // Your custom code here return $r; }
Parameters
- $r (string): The HTML output of paginated links.
- $args (array): An array of arguments. See
paginate_links()
for information on accepted arguments.
More information
See WordPress Developer Resources: paginate_links_output
Examples
Add a custom CSS class to pagination links
add_filter('paginate_links_output', 'add_custom_css_class', 10, 2); function add_custom_css_class($r, $args) { $r = str_replace('<a class="', '<a class="custom-class ', $r); return $r; }
Wrap pagination links in a div container
add_filter('paginate_links_output', 'wrap_pagination_links', 10, 2); function wrap_pagination_links($r, $args) { $r = '<div class="pagination-container">' . $r . '</div>'; return $r; }
Change the previous and next text
add_filter('paginate_links_output', 'change_prev_next_text', 10, 2); function change_prev_next_text($r, $args) { $r = str_replace('« Previous', 'Previous Page', $r); $r = str_replace('Next »', 'Next Page', $r); return $r; }
Remove the current page number from the pagination links
add_filter('paginate_links_output', 'remove_current_page_number', 10, 2); function remove_current_page_number($r, $args) { $current_page = $args['current']; $r = preg_replace('/<span class="page-numbers current">' . $current_page . '<\/span>/', '', $r); return $r; }
Add custom query string to pagination links
add_filter('paginate_links_output', 'add_custom_query_string', 10, 2); function add_custom_query_string($r, $args) { $r = str_replace('">', '?custom_query=value">', $r); return $r; }