December 30, 2024
1 min read
WordPress Next and Previous Post

Wodpress next and previous post navigation is very important to increase visitor spending time on your site.

TO show the next and previous post we can use this code in any single.php page. First, let’s call 2 variable

Vairable
<?php 
$previous = get_previous_post();
$next = get_next_post();
 ?>

Then use this code for previous post

Previous post
<?php if ( get_previous_post() ) {?>
<a href="<?php echo get_the_permalink($previous) ?>">
    <img src="<?php echo get_the_post_thumbnail_url($previous) ?>" alt="">
    <div>
        <h3> <?php echo get_the_title($previous) ?></h3>
        <p> PREV</p>
    </div>
</a>
<?php }?>

This one for Next post of that post type

Next Post
<?php if ( get_next_post() ) {?>
<a href="<?php echo get_the_permalink($next) ?>">
    <img src="<?php echo get_the_post_thumbnail_url($next) ?>" alt="">
    <div>
        <h3> <?php echo get_the_title($next) ?></h3>
        <p>Next</p>
    </div>
</a>
<?php }?>

That’s simple. It work on custom post single page too. 😉

Leave a Reply

Your email address will not be published. Required fields are marked *

Allow Only Business Email Addresses in the Email Field of Elementor Forms

Find out how to restrict email fields in Elementor forms to business emails only. Improve form data quality by blocking free email domains like Gmail and Yahoo.

Enable Leverage browser caching & Compression

To speed up your website and get good score, Enable Leverage browser caching & Compression

Add Classe when the item visible

Add class on scroll to viewport jquery code

WooCommerce Discount based on Cart Item

A discount on the total order with condition based on our cart item

Web Development Project in mind?

if you looking for a web developer for paid contribution to your project I am available for work.

Mukto
Mukto

Click the button below to chat with me.