• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

WP SITES

2784

Original Genesis Tutorials & 6000+ Guaranteed Code

Snippets

  • Consultation
  • Full Access
  • Log in

Adding Next & Previous Post Nav Links In Genesis

I’ve already shown you how to add next and previous post links in themes which include a single.php file.

Update: You’ll find more solutions with this more recent post titled Different Ways To Add Post Navigation (Pagination) In Genesis

Genesis child themes don’t include single.php files which you can use for this purpose so you need to write a custom function.

You’ll also need to hook it into the location you want to display the post navigation links.

To do this we’ll use one of the Genesis action hooks. Can’t use the Genesis Simple Hooks plugin for this because the links would then display on the archives pages which isn’t a good look. Unless you add a conditional tag to display the links on single posts only.

add_action( 'genesis_entry_content', 'custom_single_post_nav', 12 );
function custom_single_post_nav() {

	if ( ! is_singular( 'post' ) )
		return;

	echo '<div class="pagination-previous alignleft">';
	previous_post_link('%link', 'Previous Post', FALSE);
	echo '</div>';

	echo '<div class="pagination-next alignright">';
	next_post_link('%link', 'Next Post', FALSE);
	echo '</div>';

}

Linking Specific Custom Post Type

What if you use a custom post type for a portfolio or something like that? How do you add links only for the posts assigned to that type? Here’s a tutorial about how to add next and previous links only for posts assigned to one specific custom post type.

Related Tutorials

  • Cool Previous & Next Links
  • Add Next & Previous Product Navigation Links To WooCommerce Single Products

Pagination

Reader Interactions

Comments

  1. Kolbi says

    September 14, 2014 at 4:28 am

    Ahh. Nvm, I’ve figured it out. Your website is a life saver bud.

    Log in to Reply
  2. Kolbi says

    September 14, 2014 at 4:22 am

    Hey Brad! Quick Question! In the code, you say that if we want to add post titles, we need to change the “no” to “yes” . I can’t find where that No is located in the hook! Any suggestions?

    Log in to Reply
    • Brad Dalton says

      September 14, 2014 at 11:28 am

      In Genesis, you only need to use one line of PHP code to do that which i provided a link to above.

      Log in to Reply
  3. Chess Edwards says

    September 7, 2014 at 6:13 pm

    Using the code below worked perfectly! thanks!!

    How do I call out the font being used so that I can style it?

    Log in to Reply
    • Brad Dalton says

      September 7, 2014 at 9:27 pm

      The above code includes different class for each link however you can wrap both in a div or use this tutorial

      .nav-previous,
      .nav-next {
          font-family: Georgia;
          font-size: 24px;
      }
      Log in to Reply
  4. angela says

    July 9, 2014 at 6:37 pm

    Where exactly do I paste this? Genesis is a bit of mystery to me.

    Log in to Reply
    • Brad Dalton says

      July 9, 2014 at 6:42 pm

      Use this code instead which you can add to the end of your child themes functions.php file.

      add_action( 'genesis_entry_content', 'genesis_prev_next_post_nav', 12 );

      Works on HTML 5 themes only.

      Log in to Reply
  5. Justin says

    March 19, 2014 at 8:52 am

    Hi

    Great post, and the category code is excellent.

    Please can you suggest how to add the post title display to the category links.

    Also, what’s the best way to make the post title link an html link to the post it represents or is this automatic if you display post title

    thanks

    Log in to Reply
  6. MarieDenee says

    October 29, 2013 at 3:35 am

    What would the call out be to style this? Right now I have them in, but the styling is a bit off… If you could point me in the right direction, it would be awesome.

    Log in to Reply
    • MarieDenee says

      October 31, 2013 at 8:19 pm

      Just wanted to check on this one again… how can I make this float out evenly? or what would the call out be on this for me to style in CSS? right now it is jumbled to the left

      Log in to Reply
      • Brad Dalton says

        October 31, 2013 at 8:24 pm

        You would need to add a class the PHP code to style it with CSS. That code doesn’t include a class as i have written another post which does.

        Log in to Reply
      • Brad Dalton says

        October 31, 2013 at 9:26 pm

        Here’s the CSS code i use on my own site with different PHP code for linking posts within categories:

        .previous-post-link {
        float: left;
        }
        
        .next-post-link {
        float: right;
        text-align: right;
        }

        This CSS won’t work with the PHP code you are using. You will need to use the same PHP code as i use:

        // Add category post navigation (requires HTML5 theme support)
        add_action('genesis_entry_footer', 'wpsites_nav_links', 25 );
        function wpsites_nav_links() {
        if( !is_single() ) 
              return;
         
            previous_post_link('<span class="single-post-nav previous-post-link">%link</span>', '&lt;&lt; Previous Post in Category', TRUE);
            next_post_link('<span class="single-post-nav next-post-link">%link</span>', 'Next Post in Category &gt;&gt;', TRUE);
        }
        Log in to Reply
  7. Sarah says

    October 18, 2013 at 8:52 pm

    In HTML5 the hook is ‘genesis_after_entry_content’ – took me a little too long to work that one out!

    Log in to Reply
    • Brad Dalton says

      October 19, 2013 at 5:19 am

      Thanks for sharing Sarah

      Log in to Reply
  8. Mark Besh says

    December 5, 2012 at 1:25 pm

    Brad,
    Can’t ‘pin’ these anymore—doesn’t have a “pinnable image.”

    Log in to Reply
    • Brad Dalton says

      December 5, 2012 at 1:41 pm

      Hi Mark

      I pinned this to Pinterest just now. Checked to make sure it has a featured image. Worked fine.

      Log in to Reply
      • Mark Besh says

        December 5, 2012 at 1:54 pm

        Brain,
        Hmmm. Doesn’t ‘pin’ for me (the only image I see on this post is your pic, and evidently it not being picked up). What do you mean be making sure “it” has a “Featured image”?

        Log in to Reply
        • Brad Dalton says

          December 5, 2012 at 2:01 pm

          All posts include a featured image which are attached to any social sharing. If i didn’t have a featured image attached, Jetpack would pull the first image which was uploaded to the post. If no images uploaded then no image can be pinned. Sometimes the system might pull an image from the sidebar if there’s no other image to pull however i’ve found its working really well with Jetpack.

          Did you have any problem on other posts or only this one?

          Log in to Reply
          • Mark Besh says

            December 5, 2012 at 2:15 pm

            Brad,
            This just started today (a few of them that didn’t have an image ‘in-line’ the content). Maybe you could always have an image in the ‘header’.

          • Brad Dalton says

            December 5, 2012 at 2:18 pm

            Yeah i really need a logo or something. Working on a ripper Infographic at the moment as well. I’ll add an image to the sidebar now Mark. Thanks for letting me know about the problem.

  9. sach says

    December 1, 2012 at 5:35 pm

    Hi, will this one checks whether there’s no next post (for the very first post) and previous post (for the very last article)

    Log in to Reply
    • Brad Dalton says

      December 1, 2012 at 5:43 pm

      I think so because if you look after the post content on the latest post there’s NO next post, only a previous. Did that answer your question Sach?

      Log in to Reply

Leave a Reply Cancel reply

You must be logged in to post a comment.

Primary Sidebar

Code written by Brad Dalton specialist for Genesis, WooCommerce & WordPress theme customization. Read More…

Advertise · WPEngine · Genesis · Log in

  • Access Problems
  • Account Details
  • Consulting
  • Tags