Functions such as get_next_posts_link allow you to get the HTML link to the next page, with few parameters for change (label and max pages). I want to get the URL to the next page so I can add custom classes to the link.
Leave a Reply
You must be logged in to post a comment.
Why build the link yourself, when you can just add the class to the result of
get_next_posts_link()
?Now the link sent back by
get_next_posts_link()
will have your class in it.While a lot of common functions can be found on the WordPress Codex, there are also still undocumented functions in the source code.
The previous_posts function is one such function, which is documented in the source:
Using previous_posts(false), we can get the previous page’s URL, without displaying.
However this doesn’t check for when there are no more pages, and will return 404s if used on it’s own.
Inspecting the source of get_next_posts_link, we can use the code for checking if we have reached the page boundary, and return just the link: