WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I found this code :

    // Get total number of pages
    global $wp_query;
    $total = $wp_query->max_num_pages;
    // Only paginate if we have more than one page
    if ( $total > 1 )  {
         // Get the current page
         if ( !$current_page = get_query_var('paged') )
              $current_page = 1;
         // Structure of “format” depends on whether we’re using pretty permalinks
        $permalinks = get_option('permalink_structure');
        $format = empty( $permalinks ) ? '&page=%#%' : 'page/%#%/';
        echo paginate_links(array(
              'base' => get_pagenum_link(1) . '%_%',
              'format' => $format,
              'current' => $current_page,
              'total' => $total,
              'mid_size' => 2,
              'type' => 'list'

It works ok but it generates pagination like "1, 2, 3 ... LASTPAGENUMBER", I've seen plugins that generate paginations like this "1, 2, 3... 19, 20, 30 ... LASTPAGENUMBER".

Can this be achieved using paginate_links() function?

I don't want to add a plugin just for this small tweak.

share|improve this question

The paginate_links() function does this by default. The controlling parameter is mid_size, which determines the number of page links around the current page to display. The default value is 2.

What this means is that, assuming you have 12 pages, and the current page is Page 1, the pagination will look like:

1 2 3 ... 12

But if the current page is Page 6, the pagination will look like:

1 ... 4 5 6 7 8 ... 12

I could be mistaken, but I think that's how must pagination-link Plugins work.


Sorry, I misread your question at first, and didn't grasp that you want to output every tenth page in your pagination links.

This function doesn't have a built-in parameter to do what you want. Your best bet might be to set 'show_all' to true, change 'type' to 'array', and then construct the output yourself, by looping through the array values.

share|improve this answer


What you are looking for is 'end_size', add this to argument array with the value you want.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.