Skip to main content
1 of 3

I think this is a better and cleaner approach of what you are trying to achive.

// get_adjacent_post will return $post object
$prev_post = get_adjacent_post(true,'',true);
//Using get_the_post_thumbnail() to get featured image of previous post
$prev_thumbnail = get_the_post_thumbnail( $prev_post->ID, array( 100, 100));

$next_post = get_adjacent_post(true,'',false);
//Using get_the_post_thumbnail() to get featured image of next post
$next_thumbnail = get_the_post_thumbnail( $next_post->ID, array( 100, 100));

the_post_navigation(
    array(
        'in_same_term' => true,
        'next_text' => '<p class="meta-nav">'. $next_thumbnail .'Next Post &rarr;</p><p class="post-title">%title</p>',
        'prev_text' => '<p class="meta-nav">'. $prev_thumbnail .'&larr; Previous Post</p><p class="post-title">%title</p>',
    )
);