• US: +1 347 223 5853   UK: +44 20 8 1234 790
  • Live Chat

WP code for “previous post” and “next post” (single.php)

  •  admin
  •  Dec 31, 2022

Here is how to code the links to the “previous” and the “next” post under a WordPress post in single.php.

Link to the previous post


<?php
$prev_post = get_adjacent_post(false, '', true);
if(!empty($prev_post)) {?>
<a href="<?php echo get_permalink($prev_post->ID);?>">
<i class="fa fa-angle-left"></i> Previous posts
<?php echo $prev_post->post_title;?>
</a>
<?php }?>

 

Link to the next post


<?php
$next_post = get_adjacent_post(false, '', false);
if(!empty($next_post)) {
?>
<a href="<?php echo get_permalink($next_post->ID);?>">
Next posts  <i class="fa fa-angle-right"></i>
<?php echo $next_post->post_title;?>
</a>
<?php }?>

 
admin

Other posts by

It might say something like this :. Copyright © 2024 issaquah garage door services.