How to Add Pagination to Your WordPress Blog

How to Add Pagination to Your WordPress Blog

When it comes to running a successful blog, making sure your readers have a smooth user experience as they read your content is just as important as creating quality and engaging content.

A great way to improve their user experience, especially if you have a lot of posts, is to make sure your blog has pagination enabled.

Pagination is a standard feature in almost every WordPress blog and it’s also a part of WordPress itself. The main role of the pagination feature is to facilitate readers’ browsing through all the posts on your site by splitting them up into pages.

This eliminates the need to display all the posts on a single page which would inevitably slow down your site, not to mention frustrate your readers.

Nowadays, almost every theme has pagination built in. However, if you’re using a theme that doesn’t have it or if you want to try your hand at making a custom WordPress theme, you can easily add pagination yourself.

As with anything WordPress related, you can add the pagination manually or use a plugin. We’ll cover both methods below and explain where you can find pagination settings in WordPress.

Where Are Pagination Settings in WordPress

As mentioned earlier, pagination is a part of WordPress core, which means you can view and control the settings for pagination right from your WordPress dashboard.

To start, log into your WordPress site and navigate to Settings > Reading. On this page, you can set up the page that will be used for your blog posts. That page is also where your pagination will be visible.

After your blog page has been setup, scroll down until you see the text that reads:
“Blog pages show at most”.

By default, this number is set to 10, however, you can set it to be lower or higher than the default setting.

After you’ve adjusted this, you can click Save settings. If you visit your blog page now, you’ll notice that after the number of posts you’ve just set, subsequent blog posts will show up on the next page.

In some cases, you’ll see the pagination showing up as Older posts and Newer posts. Alternatively, your theme might display a numbered pagination. How the pagination is displayed, will depend largely on your active WordPress theme.

Now that we’ve covered where pagination settings are, let’s talk about adding pagination in case your theme doesn’t display it.

Adding Pagination Manually

Adding pagination manually to your blog is not as hard as it seems. All it takes is a couple of lines of code and making use of the “paginate_links” function which is a part of WordPress since 2.1 release. This function allows you to create paginated style navigation on your site.

To use it, copy the following code and then paste it at the end of your functions.php file.

function my_pagination() {
    global $wp_query;
 
    $total_pages = $wp_query->max_num_pages;
 
    if ($total_pages > 1){
        $current_page = max(1, get_query_var('paged'));
 
        echo paginate_links(array(
            'base' => get_pagenum_link(1) . '%_%',
            'format' => '/page/%#%',
            'current' => $current_page,
            'total' => $total_pages,
        ));
    }
}

Now that you’ve added the function to your functions.php file, you need to actually add it to the page where you want to display the pagination. In most cases, this will be either your index.php, home.php, category.php, tags.php, archive.php or search.php files.

In this case, we’ll be adding it to the index.php file so we need to paste the following bit of code just before the end of the regular WordPress loop. Paste the code after the “endif” statement, but before “endwhile”.

 

Adding Pagination With a Plugin

Alternatively, you can add the pagination to your blog with the help of a plugin. This method is recommended if you’d rather not get your hands dirty with code.

While there are a lot of pagination plugins out there, one of the most popular plugins is WP-PageNavi.

WP-Page Navi is an easy to use plugin that replaces the Older posts and Newer posts links with numbered pagination. To get started with WP-Page Navi, install the plugin and then activate it. Then, navigate to the plugin settings page by going to Settings > PageNavi.

As you can see from the screenshot below; you can control the page navigation text as well as the display options. You can select the text that displays for next and previous links, when to show the pagination and the format of each section of pagination.

If you’re code savvy, you can also use WP-Page Navi with a custom theme of your own in place of the built-in WordPress pagination. To do that, all you have to do is find calls to next_posts_link() and previous_posts_link() and replace them with this line of code:

You can then use the plugin’s settings page to customize how the pagination looks on your site as well as create custom CSS that controls how the pagination appears on your site.

Add Pagination to Your Blog

Adding pagination to your blog is not as difficult as it seems. Before the paginate_links function, adding this functionality into your theme or a blog was tricky, however, since WordPress 2.1, you can easily add it yourself.

Use the article above as your guide to add a simple pagination to your site with the paginate_links WordPress function or to add it via plugin with WP-Page Navi if you prefer not to delve into code.

Like This Article?

I have tons of great free content and giveaways! Join 10,000+ others and get access to coupons, freebies, and other great wordpress tips and tricksfor your wordpress website!

DW Staff

DarrelWilson.com provides free and helpful WordPress tutorials for users of all experiences and backrounds. Darrel provides free tutorials on his youtube channel. You can view the youtube channel here: https://www.youtube.com/c/darrelwilsonbug

This Post Has 2 Comments

  1. One of the best way to add pagination to WP website – using plugin for pagination. For example WP-Paginate – simple and flexible pagination plugin.

Leave a Reply

Close Menu
Hi, Sign Up For Freebies And Wordpress News!

Hi, Sign Up For Freebies And Wordpress News!

Join My Mailing List For Tips, News, And Discounts!

You have Successfully Subscribed!

×

Cart