Custom pagination for WordPress themes

See how to easily echo a custom pagination with WordPress templates.

WordPress does offer the paginate_links($args) function which is quite flexible – however, it still has some limitations and sometimes is just not good enough (e.g. when it comes to CSS classes). That’s why I made this function – it generates all of the HTML itself so we have complete control over it:

It retrieves the page count from the global $wp_query variable and also the current page number from the global $paged variable. This allows us to just call the function without the need to pass any arguments to it.

The function has just one argument which is $range. This argument specifies how many numbers should be visible back and forth from the current page number. The default value for this argument is 2, meaning 2 items before the current page, the current page number itself and 2 items after the current page will be displayed, total of 5 links.

Share on FacebookTweet about this on TwitterShare on Google+Share on Tumblr

Comments (0)