1

I would like to exclude the post format "image" from the navigation at the bottom of my single posts.

How would I be able to amend the following code to exclude the "images" post format?

if ( ! function_exists( 'sparkling_post_nav' ) ) :
function sparkling_post_nav() {
    // Don't print empty markup if there's nowhere to navigate.
    $previous = ( is_attachment() ) ? get_post( get_post()->post_parent ) : get_adjacent_post( false, '', true );
    $next     = get_adjacent_post( false, '', false );

    if ( ! $next && ! $previous ) {
        return;
    }
    ?>
    <nav class="navigation post-navigation" role="navigation">
        <h1 class="screen-reader-text"><?php _e( 'Post navigation', 'sparkling' ); ?></h1>
        <div class="nav-links">
            <?php
                previous_post_link( '<div class="nav-previous">%link</div>', _x( '<i class="fa fa-chevron-left"></i> %title', 'Previous post link', 'sparkling' ) );
                next_post_link(     '<div class="nav-next">%link</div>',     _x( '%title <i class="fa fa-chevron-right"></i>', 'Next post link',     'sparkling' ) );
            ?>
        </div><!-- .nav-links -->
    </nav><!-- .navigation -->
    <?php
}
endif;
1

1 Answer 1

0

At the beginning of your function add:

if ( has_post_format( 'image' ) ) {
    return;
}
1
  • Actually that just removes the navigation, it doesn't filters the output. To amend the results you would need to filter get_adjacent_post is some way. Commented Jul 30, 2015 at 23:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.