Using WordPress ‘paginate_links_output’ PHP filter

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_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;
}
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;
}
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_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;
}