WordPress Pagination is not working in Homepage -(Solved)

It is a weird problem when you find that pagination is not working in the homepage. I also had the similar problem when I tried to add pagination in my website’s homepage. I have done my research for several hours, and finally, I figured out that this pagination is not working in homepage just because I have used a custom homepage template. Let’s try to explain why it happens.

WordPress Pagination is not working in Homepage: Why Not working?

When you select a custom template as your homepage, it can not run it’s query properly like a regular page. That’s why the pagination is messed up and doesn’t work correctly. So let’s try to find out how it works.

Query for Pagination Support:

<?php 
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$posts = new WP_Query(array(
'post_type' => 'post',
'posts_per_page'=> 5,
'paged' => $paged ) 
); ?>


<?php if ($posts->have_posts()) :
while ($posts->have_posts()) :
$posts->the_post();
?>

Call the function to show the pagination:

<?php
the_posts_pagination(array(
    'show_all' => false,
    'prev_text' => '< PREV',
    'next_text' => 'Next >',
    'screen_reader_text' => 'Navigation',
    'before_page_number' => '<b>',
    'after_page_number' => '</b>'
));
?>

Here we use the variable $paged = get_query_var(‘paged’) to determine the current page location according to the WordPress functionality. But when we use a custom template as our homepage, this function is unable to run its query in homepage. That’s why pagination is not working properly.

WordPress Pagination is not working in Homepage – Solution:

WordPress Pagination is not working in Homepage

So let’s learn how to solve this weird problem. At first, we have to figure out if using a homepage custom template is mandatory in our theme. If it is impossible to avoid using a custom template, we have to create the pagination in our index.php file. Otherwise, we can make index.php as our website’s homepage instead of using a custom template. And then it should work properly.

Here is how I have solved the problem of “WordPress pagination is not working properly on the homepage.” It is quite simple to understand. But I had to spend several hours to figure out the actual reason. Hope you know how it works.

If you are still having the same problem after trying several methods, please don’t hesitate to contact us using the contact us form. Our team will help you to solve this problem as soon as possible at a very reasonable price.

There are many ways to solve this problem. I would recommend you to visit the official WordPress pagination link for more help and in-depth explanation.
https://codex.wordpress.org/Pagination

In the meantime, I would recommend you to visit our other pages to know more about WordPress Website Building. Thanks for visiting Let’s Learn now website. Have a great day and happy website making.

LLN Team

About The Author : LLN Team

We are LLN Team promise you to provide you useful information about website and blog creation. We will focus on WordPress and other essential needs. Keep browsing Lets Learn Now. Cheers

Leave a Reply

Your email address will not be published.

Please post a relevant comment and make the conversion informative.