WordPress Next And Previous Post | Code For Developers

WordPress Next and Previous Post

WordPress Next and Previous Post navigation for custom post type and defult blog post simple php code to use single page

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. 😉

Previous Code

Filter custom post type by Custom Field (ACF) in the admin area

Show filter on custom post type admin area with cu ...

Next Code

Get WooCommerce product info

Show product info in the place as you wish to. It ...

Leave a Reply

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

If you find it useful

Buy me a coffee

ACF

Elementor

JavaScript

jQuery

Others

PHP

WooCommerce

WordPress

Add Custom element item in wp nav menu

Add Element on last item of wp nav menu ...

WordPress category or taxonomy list

WordPress custom taxonomy term list with function ...

Change WordPress URL in Database with phpMyAdmin and SQL query

Replace WordPress old URL to new URL with SQL Quer ...

Create a new WordPress administrator via functions.php & FTP

...

Remove Website field from WordPress comment & Change cookies remember text

Remove Website field from WordPress comment & Chan ...

top