[WordPress] Pagination Without a Plugin

Coding
11 November, 2016

[WordPress] Pagination Without a Plugin

I really hate using plugins, whenever I can I try to use my own code, or code that a found on the internet for something specific.

There is some nice plugins to show post pagination on your WordPress site, like the famous WP-PageNavi, but they aren’t really necessary if you only want to add a simple navigation. Here’s how you can do it…

First you create a function on your functions.php file, this function will check for how many pages there is and display the number. You can chose how many numbers to show, in this example we are only going to show 5 pages, the current one and the next 2 anos and the past two one, plus the next and previous buttons. You can change how much you want to show by changing the number “2” in the code.

Next, you need to add this next code after a WordPress query, where you want to show the pagination.

And that’s it! Now you have your own pagination! You can style it using CSS, but in this case I’m using bootstrap classes, so, there’s no need to add CSS.

Comment