How to Display (Navigation) Links to Previous and Next Posts on your Blog Entry (WordPress)

Many WordPress themes by default do not have the previous post and next post buttons on the single post page, that is when you open a particular post from the main WordPress blog. If I like a particular post that I come across, its very likely that I’ll dig through the rest of the posts on that blog. And for that, I don’t like to load the blog-home-page each time after reading a blog entry.So, previous and next post navigation-buttons are quite an indispensible features of a blog that I love to see on whatever blog I read.

A template file of a WordPress blog is basically a PHP file and the way your single post page displays is determined by a file called single.php which is present in your \wp-content\themes\yourtheme\ directory. So, you get an idea that for adding the previous and next post links (or buttons, whatever you choose) , we’ll have to edit this file called single.php

Now let’s see how we do it. Take a look at how a most basic single.php file can look like


<!–This is the loop that checks if there are any posts to display. If there’s no post a custom error message is displayed.Else the requested post shows up!–>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

<!–This is the navigation that we intend to add to a blog entry. As this is placed above the title of my post (see the next piece of code) , the previous and next buttons appear above the title of my blog post–>
<p><?php previous_post_link(‘« %link |’) ?> <a href=”<?php bloginfo(‘url’); ?>”>Home</a> <?php next_post_link(‘| %link »’) ?></p>

<!–This shows the post title–>
<h1 id=”post-<?php the_ID(); ?>”><a href=”<?php echo get_permalink() ?>” rel=”bookmark” title=”Permanent Link: <?php the_title(); ?>”><?php the_title(); ?></a></h1>

<!–This displays the author name below the title of the post–>
<p><b>By <?php the_author(); ?></b> | <?php the_time(‘F j, Y’); ?></p>

<!–This part shows the main blog entry–>
<div class=”postspace2″>
<!–content with more link–>
<?php the_content(‘<p class=”serif”>Read the rest of this entry »</p>’); ?>
<!–for paginate posts–>

<!–This part is the footer of the blog-post that shows the categories and comments–>
<?php link_pages(‘<p><strong>Pages:</strong> ‘, ‘</p>’, ‘number’); ?>
<p><b>Topics:</b> <?php the_category(‘, ‘) ?> | <?php edit_post_link(‘Edit’, ”, ‘ | ‘); ?> <?php comments_popup_link(‘No Comments »’, ‘1 Comment »’, ‘% Comments »’); ?></p>

<div class=”postspace”>
<!–almost all options over and out–>

The text inside <!– –> in the code are comments that only describe what a piece of code does. I have elaborated them for your convenience, here. They may not be exactly the same in your template.

So what you basically need to add navigation (like on my blog’s single blog entry) is this piece of code:

<p><?php previous_post_link(‘« %link |’) ?> <a href=”<?php bloginfo(‘url’); ?>”>Home</a> <?php next_post_link(‘| %link »’) ?></p>

<?php previous_post_link(‘« %link |’) ?> : This part shows the name of the previous post, hyperlinked to it. The | character after %link shows as | to separate this link from the rest of the links we are going to add. That is link to the home page and to the next post.

<a href=”<?php bloginfo(‘url’); ?>”>Home</a> : This part shows the text Home linked to the home page

<?php next_post_link(‘| %link »’) ?> : This part shows the name of the next post, hyperlinked to it after the | symbol.

This is a simple and very useful navigational aid. But thats not all about it. Only a few people know that this is a good way to improve your internal linking for SEO purposes. Your post will always link to two posts and the homepage with the very appropriate anchor text, that is the title itself.

So, if you don’t have this feature on your blog’s single blog entry page, go ahead, add it as shown above and reap the benefits 😉 I hope this PHP tutorial helps you.

Subscribe to Inspirit’s RSS feed for receiving any future updates right in your e-mail.
This entry was posted in Blog Optimization, Blog Post, How-to and tagged , , , , , , , , . Bookmark the permalink.

32 Responses to How to Display (Navigation) Links to Previous and Next Posts on your Blog Entry (WordPress)

  1. Very good..I think mainly for SEO, because few readers click on those.


    Alex at’s last blog post..Increasing Blog Stickiness

  2. Thanks for this and for being “do follow”. 🙂

    RT Cunninghams last blog post..Building Backlinks with Blogs that Do Follow, not No Follow

  3. Geoserv says:

    Perfect, thanks a lot.
    VOTED for you at NewsDot

    Geoservs last blog post..Trackback?

  4. Howie Black Hat Reviews says:

    Hey look at me! I’m spamming your blog with my comment! Can you do the same? – Howie

  5. Now that\’s something to think about. Glad I stopped by – keep up the good work.Ciao!

  6. Free Wii says:

    Cheers for the info, will come in handy with my new website project

  7. Very helpful, and instructive. Thanks a lot, i will surely try this on.

  8. Very convenient code, i would say you did a commendable job by writting and sharing these codes.

  9. wu yi tea says:

    This code is really of great help , and linking up is so important in the websites.
    thanks for sharing.

    wu yi teas latest published blog-post ………. Day Fourteen – Two Weeks and Thirteen Pounds

  10. Gregor@Smartphones & Accessories says:

    In addition I would suggest to read some documention about how to create a theme on WordPress official site.

    Gregors latest published blog-post ………. Nokia: Global mobile phone market will fall in 2009

  11. Thanks for sharing these codes, i really have a pain writting codes, thanks a lot again !

  12. Very serviceable codes, and they are easy to implement as well.. thanks.

  13. Fling,com says:

    Very beneficial and serviceable codes. thanks alot for sharing.

  14. Joel says:

    Hello I need your help!!!!
    In my index.php..I confused because i already coded the previous_posts_link()…lines,but I cant see it.Is that possible that I see the the links even in I’m in the local..

  15. Very nice post… this sure is something too technical for people like me, aren’t there any plugins?

    UNOBLOGGERs latest published blog-post ………. What are Keywords?

  16. Abd el rahman says:

    thanks alot for sharing

  17. How to edit pictures says:

    First time i tried it didn`t work (I blew it somewhere), so i tried again. And it worked. Thanks.

  18. Ah, great post. I do not do this on my blog and I should. It entices the reader to stay on your blog. Thanks for the how-to!

  19. Great tutorial brother. Working perfectly with my wodpress blog 2.7

    Asifs latest published blog-post ………. GreenPhone | Battery Extender | Nokia

  20. Hello…

    I am working on PHP. I will defiantly use your tips for creating my blog. You have give very nice information. Thanks for sharing with us such a nice post.

    Joomla Expert

  21. Hospitalitystaff says:

    Wow………….,nice post
    I can see you have put a lot of work into it.I have being reading your posts about. I can see how this benefits everyone.Thankyou

  22. very interesting post and very usefull
    thank you for sharing
    .-= el acido folico´s last blog ..¡Hola, mundo! =-.

  23. Ganry81 says:

    Is it an open source project or not? ,

  24. Loy80 says:

    Broil until cheese is browned and zucchini is barely tender, about 5-7 minutes. ,

  25. Lea says:

    This is one of the features that are being neglected by webmasters. I’ll definitely add this buttons in my blog. Thanks for the code.
    .-= Lea´s last blog ..Resellers =-.

  26. Erken rezervasyon says:

    Thank you for your informative article and comments

  27. Moto Kurye says:

    LOL – love the phrase ‘mango-fu’ – gonna use both the phrase and the technique myself now 🙂
    .-= Moto Kurye´s last blog ..Yıldız Kurye =-.

  28. conversation says:

    nice article,thanks for the tips .. they were useful like the everyone said

  29. Yani says:

    I’ll try to apply this type of programming in my next project. Thanks for sharing this info.

  30. I really enjoyed your article, I tweet!

Leave a Reply

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