Main Content

How to get separate previous and next page/post links in WordPress.

wordpress logoI’ve been doing a lot of custom WordPress work lately and one thing that stuck me as odd was how confusing it was to get separate previous and next links for pages or posts. Turns out, it’s very simple.

There’s actually only one piece of code. To get separate links, leave parts of the code blank.

posts_nav_link('','Previous Link','');
posts_nav_link('','','Next Link');

The code will add in the links for you and you can put a DIV around each piece of code so that you can target the links with CSS to create your custom styles. Or do whatever you want.

Not sure why I had issues figuring it out, but I thought I’d share incase anyone else had the same confusion.

Leave a Reply