WordPress get next/previous post URL

This method works for WordPress posts as well as custom post types.

Use the following code inside of the WordPress loop to extract the next and previous post links.

...
$pp_url = get_permalink( get_previous_post()->ID );
$np_url = get_permalink( get_next_post()->ID );
...Code language: PHP (php)

Read more

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.