Limit the number of pages created by the paging

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.”

Thanks.

Related posts

Leave a Reply

1 comment

  1. 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.