Next And Previous Post Link In WordPress

Next And Previous Post Link In WordPress

There are many ways to navigate a WordPress site. There are archive links, category links, page links, internal post links, single post links, admin comment links, tag links, and many other types of navigational links. When it comes to navigating to Next and Previous post link on single post page then we can do like below example:

PHP Code for Next And Previous Post WordPress

<?php if ( have_posts() ) : ?>
    <div class="col-md-12" style="padding-top:30px;">
        <?php  while ( have_posts() ) : the_post(); ?>
        <h1 class="BlogTitle"><?php the_title(); ?></h1>
        <?php the_content(); ?>
        <?php endwhile; ?>
    </div>
            
    <div class="col-md-12" style="padding-top:30px;">
        <div class="next">
            <?php echo previous_post(); ?>
            <?php echo next_post(); ?>
        </div>
    </div>
<?php endif; ?>

If You want give some style to next and previous post link then you can use below CSS Code:

.next{float:left; width:100%;}
.next a{
    padding: 10px 40px;
    background: #777777;
    color: #b1d398;
    font-size: 20px;
    border-radius: 20px;
    margin-right: 20px;
    text-transform:capitalize;
}
About Author

My name is Mukesh Jakhar and I am a Web Application Developer and Software Developer, currently living in Jaipur, India. I have a Master of Computer Application in Computer Science from JNU Jaipur University. I loves to write on technology and programming topics. Apart from this, I love to travel and enjoy the beauty of nature.

Sign up for weekly update

Milkshake is almost ready. If you're interested in testing it out, then sign up below to get exclusive access.