I am trying to change the output of the previous_post_link and the next_post_link and basically add a query argument to them. The documentation just mentions that you can use the %link placeholder that is basically replaced by <a href="... the whole shebang. This does not help me, since I can't just add the query argument using simple concatenation.

Even if there is no direct way to actually use add_query_arg on the template tag, is there at least some kind of documentation regarding the placeholders that are available to me (besides %link)? If it is possible to do that and I have just the href value part available to me, I could just build my own markup with it.

I did an extensive google search on the subject and even checked the implementation of previous_post_link and next_post_link in wp-includes/link-template.php, but just the post is returned there (no mention to how this thing is themed at all).

Thanks in advance for any insight that you can provide.


previous_post_link and its sibling are pretty simple functions, so there's not a lot to play with if you really want to use these (if you're building a plugin and do not want to touch the theme, making you need a filter which isn't there).

However, since you're talking about templates, I'm guessing that you're building a theme. That gives you another option, namely building your own previous/next post link. The instrument for this is get_adjacent_post.

That function will simply give you the previous/next post as an object, leaving you all posibilities to change the permalink with add_query_arg and then build your html around it.

  • I will upvote as soon as I have enough reputation. Thanks a lot, this did the trick. I actually saw that this is the function that previous_post_link is calling internally in the link-template.php file but for some reason I didn't think to try it directly. Thanks again! – Lim Arctan Jun 22 '16 at 20:21
  • Sometimes things are easier than you think ;-) – cjbj Jun 22 '16 at 20:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.