How to add links to Previous Post and Next Post on single Posts in Genesis

Genesis has a handy function called genesis_prev_next_post_nav() which displays links to previous and next posts.

To display the prev and next post i.e., adjacent entry pagination on single posts, add this in child theme’s functions.php:

// Add single post navigation.
add_action( 'genesis_entry_footer', 'genesis_prev_next_post_nav' );

To give some breathing room below, in child theme’s style.css add

.single .adjacent-entry-pagination {
    margin-bottom: 40px;
}

Want to change the links to the generic “Previous Post” and “Next Post”?

Replace

// Add single post navigation.
add_action( 'genesis_entry_footer', 'genesis_prev_next_post_nav' );

with

add_action( 'genesis_after_entry', 'custom_adjacent_entry_nav' );
/**
 * Display links to previous and next entry.
 *
 * @since 2.3.0
 *
 * @return void Return early if not singular or post type doesn't support `genesis-adjacent-entry-nav`.
 */
function custom_adjacent_entry_nav() {

    if ( ! is_singular() ) {
        return;
    }

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

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

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

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

}

Note: genesis_next_link_text and genesis_prev_link_text filters apply to archive pagination, not single post’s.

Source: genesis/lib/structure/post.php

This site uses cookies to offer you a better browsing experience. By browsing this website, you agree to our use of cookies.