How to Add Pagination to WordPress (With Plugin and Without Plugin)

Pagination is the mechanism of splitting lists of posts or a single post into multiple pages using navigation system. Pagination is an inseparable part of any blog website. Due to its huge usability, it has become one of the core features of WordPress. Pagination enhances the user experience and decreases the loading time of website by managing the posts in various pages. It is reported that pagination also increases the SEO of your website by providing more links to your site. If your themes do not have pagination then we recommend you have one by using the methods mentioned here. In this article we will see how to add pagination to WordPress website using plugin and without using plugin.

How to add pagination to WordPress (With Plugin and Without Plugin)

Limiting the number of post to show in a page

Before adding any kind of pagination you have to first set the maximum number of post to be shown in any page. You can easily set the number of posts to be display in a page from admin dashboard. Simply go to Settings > Readings. Enter your number at the “Blog pages show at most” option and then save the settings. This value will be used by your website unless it is overridden by the theme code.

Limiting the number of post to show in a page

How to add pagination to WordPress using Plugins

Using Pagination Plugin is the simplest way of adding stylish plugin without messing with the code. If you are relatively new to the plugin check out article on “What is Plugin in WordPress and How does it work?”, Here are two most popular plugins that you can use for pagination.

1. Pagination by BestWebSoft

Pagination by BestWebSoftOur top recommended plugin is Pagination by BestWebSoft. This plugin do not require any kinds of setting and coding. This is the perfect choice for absolute beginner bloggers since it will add pagination automatically once it has been installed. Simply install and activate the plugin and you will automatically get custom pagination in all your blog, search results, archive, category, tags, and author pages.

However you still can choose pagination type, position, and customize its appearance by going to BSW Panel < Pagination.

2. WP-PageNavi

How to Add Pagination to WordPress (With Plugin and Without Plugin)

If you know a little about WordPress theme file structure, WP-PageNavi should be your first choice. This is the most popular and highly rated plugin with more than a million active downloads. The plugins has small size so it does not give much pressure to your theme. You can easily find and install the plugin from WordPress plugin repository. To use the plugin you need to have simple WordPress coding knowledge. You just have to find the location where you want the pagination to be display. Simply insert the function code given below in that location at the end of the loop. If your theme already has some kind of pagination then you can simply replace it with this code.

<?php wp_pagenavi(); ?>

This should give you the numbered pagination in your website.

Adding default WordPress Pagination without any plugin

If you have basic knowledge of WordPress folder structure, you can add the pagination yourself too using few simple lines of codes. We will be using WordPress functions next_posts_link() and previous_posts_link() to display the pagination links. First locate the page in your WordPress directory where you want the pagination to appear. Inside the page find the loop. The right place to keep pagination is after the end of ‘while’ loop and before the end of ‘if’ loop.

<div class="nav-previous">
    <?php next_posts_link( '&larr; Older posts' ); ?>
</div>

<div class="nav-next" style="text-align:right">
    <?php previous_posts_link( 'Newer posts &rarr;' ); ?>
</div>

When you save the file you should see the simple pagination links. You can even style up the pagination links with a little bit of CSS and you will have a fully functional pagination system in your Website.

Also Read:   Steps to Reset WordPress Password from phpMyAdmin

Adding numbered pagination in WordPress without plugin

If you want the fancy number pagination system in your website and don’t like using plugins then don’t worry we have a way for you too. If you have little knowledge of WordPress folder structure we recommend this way for you.All you need to do is copy these few lines of code in your functions.php file.


function pagination_bar() {
    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 to actually see the pagination simply add these line to the place where you want the pagination to appear. The best place is at the end of your loop.

 <div class="my_pagination">
     <?php pagination_bar(); ?>
 </div> 

Now if you check the front end of your website, you should see the pagination appearing. You can use some CSS styling to make it look better. Here is a piece of code to make it look better. You are free to experiment with CSS to make the pagination that match your theme.

.my_pagination a.page-numbers, .my_pagination .current{
    padding: 10px;
border-radius: 5px;
}

.my_pagination a.page-numbers{
    color: #5F5B5B;
text-decoration: none;
background: #B4C4D5;
}
.my_pagination .current{
background: #6F7B87;
color: #fff;
}

Here is the final look of my pagination.

The purpose of this article is to show different methods adding pagination to your website with confusing the readers. We hope this article on how to add pagination to WordPress was useful. You can also read our other article on “How to Add Featured Content Slider in WordPress“.

The following two tabs change content below.

Kantiman Bajracharya

Kantiman Bajracharya is a freelance web developer. He is a computer geek who has a Bachelor’s degree in Computer Engineering. He has earned lots of satisfied customers while working for numerous successful projects. He is also a WordPress theme creator and web article writer. On free time he likes reading philosophy books, traveling and playing chess.

Share This Post