WordPress: Get Single Post Previous & Next Links

Follow @tristarweb

Another quick WordPress tip for you guys. I found myself needing the code to return just the url value of the previous or next single post. For some reason there doesn’t seem to be a simple way to do it, however, I did stumble across the following codes.

Previous link:

<?php echo get_permalink(get_adjacent_post(false,'',false)); ?>

Next link:

<?php echo get_permalink(get_adjacent_post(false,'',true)); ?>

So there you have it, that’s how you can return the previous and next single post links!

About James

Hello there, I'm James. I studied Multimedia Design at university. I'm a designer at heart, though I love developing innovative and exciting solutions to web based products.I now specialise in front end web design and bespoke Wordpress powered websites.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Please wrap all source code with [code][/code] tags.

Follow Tristar on Twitter