Skip to content

Instantly share code, notes, and snippets.

@prosantamazumder
Created April 25, 2022 12:06
Show Gist options
  • Save prosantamazumder/5a0e120ee0a1bf02cd45bc167c5bbe4e to your computer and use it in GitHub Desktop.
Save prosantamazumder/5a0e120ee0a1bf02cd45bc167c5bbe4e to your computer and use it in GitHub Desktop.
Next Previous Post link in WordPress with previous post title / next post title?
<nav id="nav-single">
<?php
$prev_post = get_previous_post();
$id = $prev_post->ID ;
$permalink = get_permalink( $id );
?>
<?php
$next_post = get_next_post();
$nid = $next_post->ID ;
$permalink = get_permalink($nid);
?>
<span class="nav-previous"><?php previous_post_link( '%link', __( '<span class="meta-nav">&larr;</span> Previous', 'twentyeleven' ) ); ?>
<h2><a href="<?php echo $permalink; ?>"><?php echo $prev_post->post_title; ?></a></h2>
</span>
<span class="nav-next"><?php next_post_link( '%link', __( 'Next <span class="meta-nav">&rarr;</span>', 'twentyeleven' ) ); ?>
<h2><a href="<?php echo $permalink; ?>"><?php echo $next_post->post_title; ?></a></h2>
</span>
</nav>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment