How to Add Pagination to a WordPress Blog

Quick Summary

  • Echo paginate_links() right after endwhile in index.php, home.php or archive.php to print numbered page links for the main query.
  • Set Blog pages show at most under Settings > Reading, and use previous_posts_link() and next_posts_link() for plain Previous and Next links instead.
  • For a custom WP_Query, pass the total and current page to paginate_links() yourself, and make template edits in a child theme.

WordPress already splits your blog and archive pages into pages, but many custom themes never print the links to move between them. You can add those links with one core function, or use a plugin.

First go to Settings > Reading in the dashboard and set “Blog pages show at most” to the number of posts you want on each page.

Then open the template that lists your posts, such as index.php, home.php or archive.php, and add the pagination right after endwhile;, where the while loop ends:

PHP
<?php 
    endwhile;
    //previous_posts_link( );
    //next_posts_link( );
    echo paginate_links(  );
else: ?>
  • paginate_links() returns numbered links (1, 2, 3 and previous/next) for the main query as a string, which is why it is echoed.
  • Because it sits before else:, the links only appear when there are posts to show.
  • The two commented lines are the simpler alternative: previous_posts_link() and next_posts_link() print just a “Previous Page” and a “Next Page” link. Remove the // to use them instead of the numbers.
  • Called without arguments, paginate_links() works with the main query. For a custom WP_Query you have to pass the total and current page yourself, as in pagination for a custom WP_Query.
  • Make the change in a child theme’s copy of the template, so a theme update doesn’t remove it.

Use a plugin instead

If you’d rather not edit theme files, WP-Paginate is a simple and flexible pagination plugin that gives visitors better navigation on your WordPress site.

Share on X (opens in a new tab) Share on LinkedIn (opens in a new tab) Share on Facebook (opens in a new tab)

ChatGPT (opens in a new tab) Claude (opens in a new tab) Gemini (opens in a new tab) Perplexity (opens in a new tab) Grok (opens in a new tab)

More Insights

See More