Default WordPress themes and many other themes display pagination links by adding Older posts and Newer Posts links at the bottom of your WordPress archive pages. However, there are many WordPress sites that use numeric pagination. From our experience, numeric pagination is more user-friendly, attractive, and SEO friendly. Most advanced WordPress theme frameworks like Genesis comes with a built-in functionality for adding numeric pagination. In this article, we will show you how to add numeric pagination in your WordPress theme. The goal is to replace the default Older and Newer pagination links at the bottom of archive pages with easy to navigate page numbers.

Adding Pagination without plugin

Good pagination is very useful for allowing users to browse through your website.  Rather than “previous” or “next” links. This is where another one of our code snippets for WordPress comes into play – it adds good pagination to your content. Please place the following function Inside functions.php file

    global $wp_query;

   $total = $wp_query->max_num_pages;

   // only bother with the rest if we have more than 1 page!

       if ( $total > 1 ) {

         // get the current page

       if ( !$current_page = get_query_var('paged') )

$current_page = 1;       

       // structure of "format" depends on whether we're using pretty permalinks

       $format = empty( get_option('permalink_structure') ) ?        '&page=%#%' : 'page/%#%/';

       echo paginate_links(array(

       'base' => get_pagenum_link(1) . '%_%',

       'format' => $format,

       'current' => $current_page,

       'total' => $total,

       'mid_size' => 4,

       'type' => 'list'

       ));

       }

Adding Pagination using WP-PageNavi Plugin

Now let’s take a look at how to add numeric pagination in your WordPress theme by using an existing plugin called WP-PageNavi. The first thing you need to do is install and activate WP-PageNavi plugin.  After activating the plugin go to Settings » PageNavi to configure the plugin settings. On the plugin settings page, you can replace the default text and numeric pagination settings with your own if you want. However, the default settings should work for most websites. In the next step, you need to add a template tag in your WordPress Theme.

Go to your theme folder and find the lines for older and newer pagination in your archive page templates:

index.php, archive.php and any other archive template files. Add the following template tag to replace the old previous_posts_link and next_posts_link tags.

 global $wp_query;

   <?php wp_pagenavi(); ?>

Now pagination is added in your theme. Enjoy 🙂

Welcome to Wbcom Designs!  - Get 10% off on all plugins & themes
Coupon : HELLO10