How Do I Add Next and Previous Links On Single Custom Post Type Only?

I’d like to add next and previous post links on single posts which use a custom post type. Prefer links only work for the posts assigned to the custom post type.

How would i add it to this:

Read More
function wpsites_npp_navigation_links() {
if( 'portfolio_post_type' == get_post_type() ) {?>
<?php previous_post('&laquo; &laquo; %', 'Previous', 'no'); ?>
 | <?php next_post('% &raquo; &raquo; ', 'Next', 'no'); ?>
<?php
} }

add_action('genesis_after_post_content', 'wpsites_npp_navigation_links', 5 );

Worked this out myself. Here’s the solution for HTML 5 enabled Genesis child themes.
Change to the old hook if you haven’t added child theme support for HTML 5.

Example: From genesis_entry_footer to genesis_after_post

function wpsites_npp_navigation_links() {
if( 'portfolio' == get_post_type() ) {?>
<?php previous_post('&laquo; &laquo; %', 'Previous', 'no'); ?>
 | <?php next_post('% &raquo; &raquo; ', 'Next', 'no'); ?>
<?php
} }

add_action('genesis_entry_footer', 'wpsites_npp_navigation_links', 5 );

Related posts

2 comments

  1. A simple solution is to edit your single.php template file and wrap the calls to previous and next post link with a check of the post type:

    if( 'your_post_type' == get_post_type() ) {
        previous_post_link();
        next_post_link();
    }
    

Comments are closed.