Created
April 25, 2022 12:06
-
-
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?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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">←</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">→</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