Add prev and next post with title and thumb

Marko Krstić
20 Jun 2020

Add this in codeblock in single post template

<?php $prev = get_previous_post(); ?>

<a href="<?php echo get_permalink( $prev->ID ); ?>">

	<h3><?php echo apply_filters( 'the_title', $prev->post_title ); ?></h3>
	<?php echo get_the_post_thumbnail(
  		$prev->ID, 
  		'thumbnail',
  		array('class' => 'your-class-name')
	); ?>
  
</a>



<?php $next = get_next_post(); ?>

<a href="<?php echo get_permalink( $next->ID ); ?>">
	<h3><?php echo apply_filters( 'the_title', $next->post_title ); ?></h3>
	<?php echo get_the_post_thumbnail(
  		$next->ID, 
  		'thumbnail',
		array('class' => 'your-class-name')
	); ?>
</a>

Title is wrapped with h3 and thumbnail is having class (‘your-class-name’) that you can change to your needs.

Was this article helpful?

Tags

Categories

Never miss new post again

Subscribe and get list of new posts in your inbox

Click to Copy