How to Add Next and Previous Links on Single Post Page

Share This Article:

How to Add Next and Previous Links on Single Post Page. It is always good to have better navigation links on the blog. One such practice is to add “Next and Previous Posts Links” at the end of the post. After reading an article, readers will try to explore more from your blog and at this point related posts are really useful.

add-next-previous-links-wordpress-posts

Apart from related posts another simple yet powerful approach is to include links to “Previous” and “Next” posts. These links are also known as “Post Navigation Links” and follow this tutorial to add them to your blog.

Add Next & Previous Links on Single Post Page

Code used to display Next & Previous links is available at Codex and we modified a bit of it, so that additional CSS classes and some functionality can be included.

previous-next-posts-wordpress

If you are using a normal WordPress theme like Twenty Ten or Twenty Eleven, then follow these steps. If your blog runs on Thesis and Genesis Frameworks, do check the below guides.

  • Login to WordPress Dashboard and go to “Theme Editor”.
  • Find single.php file and open it in Editor.
  • Add below code at the end of it and click on “Update File Button”.
  • That’s it, now next and previous post links will be displayed.
/** Add Previous & Next Links in Single Post Page */
<div id="prev-next">
<div class="prev-link">&larr; Previous Post
<?php previous_post_link('%link', '%title'); ?>
</div>
<div class="next-link">Next Post &rarr;
<?php next_post_link('%link', '%title'); ?>
</div>
</div>

You need to add some styling to these links, so that they will be aligned properly and makes this whole thing attractive. To do so, check out the last part of this article.

Check :How to Disable or Limit Post Revisions in WordPress

Add Next & Previous Links in Genesis Theme

Same code will be used for Genesis Theme also, but the entire code will be wrapped up in a “Hook”, so that the links can be added at desired position on the single post page.

  • Login to Dashboard and go to “Appearance Menu”.
  • Open functions.php file in theme editor.
  • Add below code in the end and “Update” it.
  • Move on to 2nd step, i.e add CSS to the links.
/** Add Previous & Next Links in Genesis Single Post Page */
function genesis_post_navigation() {
if ( is_single ( ) ) { ?>
<div id="prev-next">
<div class="prev-link">&larr; Previous Post
<?php previous_post_link('%link', '%title'); ?>
</div>
<div class="next-link">Next Post &rarr;
<?php next_post_link('%link', '%title'); ?>
</div>
</div>
<?php
} }
add_action('genesis_after_post_content', 'genesis_post_navigation');

Recommended: Thesis 2.0 Release Date and Features List

Add Next & Previous Links in Thesis Theme

Similar to Genesis, code will be added to “Hook”. If you are new to Thesis Theme checkout our previous articles that will guide to customize thesis without any hassle.

  • Login to Dashboard and go to “Appearance Menu”.
  • Open custom_functions.php file in theme editor.
  • Add below Code to it and “Save the File”
  • Now, its time to add styling to the links.

PS: This functionality is available in Thesis by Default. If you want further control and great look, then try this one. Otherwise, no need to use this code.

/** Add Previous & Next Links in Thesis Single Post Page */
function thesis_post_navigation() {
if ( is_single ( ) ) { ?>
<div id="prev-next">
<div class="prev-link">&larr; Previous Post
<?php previous_post_link('%link', '%title'); ?>
</div>
<div class="next-link">Next Post &rarr;
<?php next_post_link('%link', '%title'); ?>
</div>
</div>
<?php
} }
add_action('thesis_hook_after_content', 'thesis_post_navigation');

Also Check: How to Add 3 Column Widgetized Footer to Genesis

Add CSS to Next & Previous Links

Here come the final and the most important step, adding CSS to the links. This is common for all the 3 cases discusses above and you need to add below code to style.css file. If you are using Thesis, then add this code to custom.css file and save.

/** CSS for Previous & Next Post Links in Single Page */
#prev-next {  float: left; margin:10px;}
#prev-next .prev-link {float: left;width: 50%;text-align: left;}
#prev-next .prev-link a {float: left;text-align: left;}
#prev-next .next-link {float: right;width: 50%;text-align: right;}
#prev-next .next-link a {float: right;text-align: right;}
#prev-next a{text-decoration: underline; }
#prev-next a:hover { text-decoration: none; }

Hope you like this awesome tutorial and if you got any query regarding this, simply drop a comment. We will get back to you soon, meanwhile subscribe to our Feeds.

Genesis is the most flexible WordPress theme framework that comes with tons of options. We have been using Genesis on all of our blogs and recommending the same to you. Every bit of it is coded according to the standards. Give it a try!

Comments

  1. Tracey says:

    Hi there — great tutorial…thank you. My only issue is that the last/next links don’t seem to land in a way that the content after them lands in their proper place. I’ve skitched a screenshot: https://skitch.com/traypup/e8g6c/solo-entertainment-lawyer-why-this-blog

    I’d like the “speak your mind” to be on the next line, clearly. Any suggestions? Thanks!

    • WPSquare says:

      You can by specifying width to #prev-next section, just modify the below code…

      #prev-next {
      float: left;
      margin: 10px;
      }

      to

      #prev-next {
      float: left;
      margin: 10px;
      width: 100%;
      }

      Hope this will help you…

      • Tracey says:

        Thank you so much — such a quick reply! I had worked this out just as I received your reply, but I really appreciate knowing I was on the right track. Thanks again!

        • WPSquare says:

          Glad it worked for you and visit again :)

  2. Tim says:

    Hi WPSquare,
    I’ve fitted your single post navigation code to my genesis child theme and I’ve got two problems. First, if I have ‘commenting’ turned on for static pages, I get navigation too. I want the navigation only on single posts – how do I stop it appearing on my static pages?
    Secondly, I’ve c&p’d your navigation CSS styling into my child theme style sheet but it does not seem to take. Please take a look at my test site at: http://timbaggaley.co.uk/test/

  3. Jit Dutta says:

    Thank you, valuable info…. works fine for me.

  4. Jack says:

    When I add the CSS my comments all disappear. When I delete the CSS the comments reappear. How can I add this CSS AND keep my comments?

Speak Your MindComments Policy →

*

Looking for More Awesomeness?

Read previous post:
wordpress-theme-marketplaces
5 Best WordPress Theme Marketplaces

5 Best WordPress Theme Marketplaces. If you are looking for high-quality WordPress themes or if you want to sell a...

Close