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

WP SITES

2785

Original Genesis & WooCommerce Tutorials & 6000+ Guaranteed Code

Snippets

  • Try Premium
  • Log in

Add Single Post Navigation In Genesis

This code enables you to reposition the single post navigation links in Genesis to any hook position.

This post also includes the code to modify the default single post navigation.

You can add the links several ways:

add_action( 'genesis_entry_footer', 'genesis_prev_next_post_nav' );

Or like this:

add_action( 'genesis_before_while', 'hook_genesis_prev_next_post_nav' );

function hook_genesis_prev_next_post_nav() {

	if ( is_singular( 'post' ) ) {
		genesis_prev_next_post_nav();
	}
}

If you need to modify the default single post navigation, you can using this code:

add_action( 'genesis_entry_footer', 'your_function' );
function your_function() {

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

	genesis_markup( array(
		'html5'   => '<div %s>',
		'xhtml'   => '<div class="navigation">',
		'context' => 'adjacent-entry-pagination',
	) );

	echo '<div class="pagination-previous alignleft">';
	previous_post_link();
	echo '</div>';

	echo '<div class="pagination-next alignright">';
	next_post_link();
	echo '</div>';

	echo '</div>';

}

Here’s an example of the above code where the 3rd parameter in the functions for the next and previous post links have been modified so only single posts within the same category are linked:

add_action( 'genesis_entry_footer', 'custom_single_nav' );
function custom_single_nav() {

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

	genesis_markup( array(
		'html5'   => '<div %s>',
		'xhtml'   => '<div class="navigation">',
		'context' => 'adjacent-entry-pagination',
	) );

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

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

	echo '</div>';

}

You can also reposition the links using code like this:

add_post_type_support( 'post', 'reposition-post-nav' );
add_action( 'genesis_after_entry', 'reposition_post_nav' );

function reposition_post_nav() {
if ( ! is_singular() || ! post_type_supports( get_post_type(), 'reposition-post-nav' ) ) {
		return;
	}

	genesis_markup( array(
		'open'    => '<div %s>',
		'context' => 'adjacent-entry-pagination',
	) );

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

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

	genesis_markup( array(
		'close'    => '</div>',
		'context' => 'adjacent-entry-pagination',
	) );
}

Modify Single Post Navigation Function #

You can modify the following code for use in your genesis child theme.

Change the code within the single_post_adjacent_entry_nav_genesis function for usage in your child themes functions file or single.php template file.

The code comes from the post.php file inside genesis.

Related Code

  • Add No Follow To Next & Previous Post Links

Pagination

Reader Interactions

Comments

  1. Kevin Eberle says

    April 21, 2022 at 5:29 pm

    How would I add a headline above the Previous / Next links.

    Ex:

    ‘Read More Posts’
    Previous Post Ttile — Next Post Title

    Log in to Reply
    • Brad Dalton says

      April 21, 2022 at 5:38 pm

      Add

      echo'<div class="yourclass">' . __('Read More Posts') . '</div>';
      Log in to Reply
    • Brad Dalton says

      April 21, 2022 at 6:03 pm

      Please send the file to brad@wpsites.net so i can test it.

      Log in to Reply
      • Kevin Eberle says

        April 21, 2022 at 6:08 pm

        Sent from taylor@ email address. Thank you.

        Log in to Reply
        • Brad Dalton says

          April 22, 2022 at 3:10 am

          Only modify the text, do not remove the single quotes wrapping the text.

          add_action( 'genesis_before_while', 'hook_genesis_prev_next_post_nav' );
          function hook_genesis_prev_next_post_nav() {
          
          	if ( is_singular( 'post' ) ) {
          	
          	echo'<div class="yourclass">' . __('Read More Posts') . '</div>';
          	
          	genesis_prev_next_post_nav();
          	
          	}
          }
          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