Previous & Next Single Post Navigation Links In WordPress

Connecting all your posts together is not a bad way to make sure all of them are indexed in the search results.

Its also not a bad way to help increase a few extra page views as some of your readers will click your next & previous post links.

But lets face it, if you’ve setup and submitted a compliant XML sitemap you shouldn’t have anything to worry about it right?

Wrong!

In reality, there’s always something to worry about like:

  • why aren’t all my url’s indexed!
  • and why aren’t i getting more traffic!!

Lets take a look at the different ways you can add next and previous navigation links to different WordPress child and parent themes.

Adding Single Post Nav Links Using Code

To add post nav links to themes which don’t already include this function in the parent or child themes files, follow these steps.

You can simply add the template tags directly to your parent theme’s single.php file

Your single.php file is one of your templates used when displaying all single posts.

Add this code before the closing WordPress loop like i have done in this screenshot.

I have removed the text parameter in green so only the previous and next post titles will be displayed.

Previous & Next Post Function
Add the Previous & Next post code before the // end of the loop.

This code will display the post titles rather than the words previous and next post.

If you want to display the words, previous and next or custom text instead of your post titles, simply change the parameter in the code from yes to no. This will remove the post titles linked to your previous and next posts and only display the text in green which you can customize.

You could also use previous and next post with both post titles as well by changing the third parameter to yes as well as adding the previous and next text in the second parameter in green.

Display Position

The navigation links will display on all single posts depending on where you paste the code in your single.php template file.

The most popular location is immediately after your post content so you would paste the code before your comments template like this:

Display Nav Links Before Comments Template
Display Post Navigation Links Before Comments Template & After Post Content On Single Posts

Adding this code to your parent themes single.php template file is not exactly best practice because you’ll lose this function when you update the theme.

Better to hook it in using an after post content action hook (theme specific) and custom function.

Post Navigation Link Plugins

There’s many of these plugins in the WordPress plugins directory.

  • WP Page Navi – Popular plugin for adding post and page navigation to WordPress.

Alternative Solution

Simply add this PHP code to your child themes functions file.

Related Code Snippets


Comments

8 responses to “Previous & Next Single Post Navigation Links In WordPress”

  1. sebastian taru Avatar
    sebastian taru

    Could we also get the post thumbnail together with the title in that hook?

  2. I am using the most recent post (1 post) on the homepage so that the next day’s title is displayed on the homepage and nothing else.

    Currently, when you click on the “Older Posts” link on the homepage eg homepage.com goes to: homepage.com/page/2/ instead of homepage.com/url_for_next_post

    The problem is that I have different backgrounds on each post so I want them to be shown rather than the post displayed over the homepage background.

    Any ideas how to achieve this?

    Thanks

    1. Brad Dalton Avatar
      Brad Dalton

      Yes but i only work for members

  3. Thank you so so much! I’m not very tech savy, and code confuses me. Ok. Let’s be honest. Many things confuse me. But your tutorial was awesome. Not only did I add the code, but I managed not to break my site. You’ve made me a believer!

    1. Brad Dalton Avatar
      Brad Dalton

      Glad to hear it Sheri!

  4. Kim Larsen Avatar
    Kim Larsen

    Hey, I followed your tutorial, and it did what it was suppose to do, which of course is great! 😉

    BUT, I was wondering if you could suggest a code to make the navigation only apply to the CATEGORY that you are currently reading? Right now this code takes you through ALL your posts in one long line.

    -Kim

    1. The category archive page does that already Kim.

Leave a Reply

Join 5000+ Followers

Get The Latest Free & Premium Tutorials Delivered The Second They’re Published.