WordPress provides several navigational template tags to make it easy for developer to create previous and next post link navigation for browsing through WordPress blog. There are basically two different types of template tags used for chronological post navigation, posts_nav_link() and previous_post_link() & next_post_link(). But there is a small problem with these template tags, that these tags output the HTML markup required to create the actual hyperlinks that will appear on your web page but they do not offer complete freedom for developers to customize these links as they want.
Sometimes you have a very specific requirement to be able to get the link URLs of previous and next posts instead of actual hyperlinks. And WordPress does not provide any function to output just link URLs. So in this article I am going to show you how to get link URLs of previous and next posts in your WordPress theme.
This little code snippet will output the link URL of next post. You should use this code in your theme files to create your custom hyperlinks for next blog post.
<?php echo get_permalink( get_adjacent_post( false, '', false ) ); ?>
Similarly this code snippet will get you link URL of previous post.
<?php echo get_permalink( get_adjacent_post( false, '', true ) ); ?>