Pagination reduces the server overhead and improves response time. In WordPress sites, pagination is mostly used in archive pages to divide a long list of posts into multiple separate pages. Some advanced or premium WordPress themes offer a built-in functionality for adding numeric pagination. There are also various custom pagination plugins available in WordPress plugins directory.
But if you are developing a custom theme or want to add a numeric pagination without installing a plugin. This post is specially for you.
Here you will learn how to add custom numeric pagination in WordPress step by step.
How To Add Numeric Pagination In Your WordPress Theme
Step1: Adding the pagination code in your theme
First, create an “inc” folder in your theme’s directory then create a file “wp-pagination.php” inside the “inc” folder. Add the following code in the “wp-pagination.php” file.
You can also directly add the code in your theme’s functions.php file.
The above code retrieves the number of pages and prepares a bulleted list of numbered links. If you have development skills, you can rewrite the function name.
Step2: Include the pagination code in functions.php
Next, we have to tell the theme’s functions.php that we have added some code in the wp-pagination.php file which is inside the “inc” folder.
If you have placed the above first code directly in your theme’s functions.php file, you can skip this step.
Step3: Adding the template tag
In the third step, add the following template tag in your theme’s index.php, archive.php, category.php, or any other file according to your need. This template tag will display numeric pagination in your WordPress website.
Step4: Styling the Pagination
Now we have to style our numeric pagination by adding the following CSS code in the theme’s style.css file.
Finally, our numeric pagination in archive page will look like this.
By default WordPress, archive pages show a maximum number of 10 posts per page. You can change the number of posts from your dashboard settings.
If you have any problems, feel free to ask questions in the comment box.