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.
Add numbered page links with paginate_links()
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
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()andnext_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 customWP_Queryyou have to pass thetotalandcurrentpage 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.
Related articles
- paging a custom post type list: the same function with a post type query and an ACF date sort
- splitting one long post into several pages: when a single post needs page links

