I'm currently using posts_nav_linkfor my posts navigation. But it hides the next/previous post link if there is no next/previous post. Ideally, for my design, it should gray out the link. If it was fairly simple also be interested in having the links simply start over at the beginning or end when there was not another post to display (I guess like a carousel).

I'm not wedded to posts_nav_link at all. I'm just not sure what would work better.

1 Answer 1


If you wanted to have a greyed out link, you could swap out posts_nav_link for something like this:

<?php if ( ! get_previous_posts_link() ) : ?>
    <div class="inactive post-link post-link__previous">« Previous Posts</div>
<?php else : ?>
    <div class="post-link post-link__previous"><?php previous_posts_link(); ?></span>
<?php endif; ?>

And just set the inactive class in your CSS to be greyed out. You then would obviously repeat the same with the get_next_posts_link() and next_posts_link() functions.

If you wanted to loop back, you could try something like this, if your homepage is setup as your posts page.

<?php if ( ! get_next_posts_link() ) : ?>
    <div class="inactive post-link post-link__next">
        <a href="<?php echo home_url(); ?>">Next Posts</a>
<?php else : ?>
    <div class="post-link post-link__next"><?php next_posts_link(); ?></span>
<?php endif; ?>

If your posts page is setup as a static page, you can grab the url for it like this echo get_permalink( get_option('page_for_posts' ) );.

Hope this helps.

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.