WordPress post pagination without plugin

WordPress post pagination without plugin

There is lots of developers who actually didn’t know how to use pagination in WordPress posts. So many people are in this field are using plugin for WordPress posts pagination but they didn’t realize that plugin makes website heavy so if pagination can work by using some functions then why should we use plugin so let me tell you that how to use pagination in wordpress post without having any plugin. Lets start with some codes.

1) Use this method for default posts

Use this code into your fucntion.php file

if ( ! function_exists( 'post_pagination' ) ) :
   function post_pagination() {
     global $wp_query;
     $pager = 999999999; // need an unlikely integer

        echo paginate_links( array(
             'base' => str_replace( $pager, '%#%', esc_url( get_pagenum_link( $pager ) ) ),
             'format' => '?paged=%#%',
             'current' => max( 1, get_query_var('paged') ),
             'total' => $wp_query->max_num_pages
        ) );

After doing this call the pagination function where you want to display the pagination.

<?php post_pagination(); ?>

you have to set post limit from WordPress backend for this you have to go to Settings >> Reading >> Select number of posts you wish to display.

2) Use this method for custom posts

All the methods should be the same but when you are using custom post type you have to use this loop for pagination.

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

    'post_type' => 'post', // You can add a custom post type if you like
    'paged' => $paged,
    'posts_per_page' => 10 // limit of posts

if ( have_posts() ) :  while ( have_posts() ) : the_post(); 

     // post content goes here...



 else : 

// no posts found message goes here...


By using this you can get pagination for WordPress posts without any plugin and your website will be load free. Hope this tutorial will be helpful to you and if you face any problem or you have any suggestion we welcomes you always.

Good Luck !

8 thoughts on “WordPress post pagination without plugin

  1. Awesome, Thanks for contributing your important time to post such an interesting & useful collection of knowledgeable resources that are always of great need to everyone. I visit this blog first time and encourage by this good stuff work. Unbelievable post keeps up posting such great information. There are things here that I didn’t think some time as of late. am very enjoyed for this weblog. It’s an informative subject matter.

  2. Thanks for your post! I think there are many other people who are interested in them just like me! How long does it take to complete this article? I have read through other blogs, but they are cumbersome and confusing. I hope you continue to have such quality articles to share!

Leave a Reply