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

Any way to limit the number of pages that are created automatically by paging? I would limit to five pages in all, authors, tags, categories ... Ex: "site.com/tag/news/page/5", "...author/admin/page/5."


share|improve this question
In the backend? – Rutwick Gangurde Jun 23 '12 at 12:43
Hi @Rutwick Gangurde In the frontend. – BóbGCA Jun 23 '12 at 12:46
The paging can be controlled if you can edit the theme files. – Rutwick Gangurde Jun 23 '12 at 12:52
up vote 2 down vote accepted

This seem to work. Put in your functions.php:

add_filter('pre_get_posts', 'limit_pages');
function limit_pages($query) {

    $query->max_num_pages = 5;
    if ($query->query_vars['paged'] > 5) {
        $query->query_vars['paged'] = 5;
        $query->query['paged'] = 5;

    return $query;

But I guess you would still need some workaround for posts pagination and authors. Hope it helps you a little.

share|improve this answer
thanks for trying @Vinicius Massuchetto, but this function has not changed. – BóbGCA Jun 23 '12 at 12:40
Well.. it is working here. Did you try accessing page/6/, page/7/, page/8/? They should all look the same. – vmassuchetto Jun 23 '12 at 12:45
Please note that this way all your posts are still directly accessible, we're just dealing with pagination here. – vmassuchetto Jun 23 '12 at 12:46
The comment is fine. Just leave it there. =D – vmassuchetto Jun 23 '12 at 13:09
Oh, sorry @Vinicius Massuchetto, now it is working. Now we need to adapt my function to display pagination links only to the number 5 (Pages: 1 2 3 4 5). Chosen to best response. Thanks! – BóbGCA Jun 23 '12 at 13:12

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.