I solved the problem by using get_the_post_thumbnail()
instead of the variables $prevthumbnail
and $nextthumbnail
.
function THEMENAME_post_nav() {
// Don't print empty markup if there's nowhere to navigate.
$previous = ( is_attachment() ) ? get_post( get_post()->post_parent ) : get_adjacent_post( false, '', true );
$next = get_adjacent_post( false, '', false );
if ( ! $next && ! $previous ) {
return;
}
?>
<nav class="navigation post-navigation" role="navigation">
<!-- <h1 class="screen-reader-text"><?php _e( 'Post navigation', 'THEMENAME' ); ?></h1> -->
<div class="nav-links">
<?php
previous_post_link( '<div class="nav-previous">' . get_the_post_thumbnail() . '%link</div>', _x( '%title', 'Previous post link', 'THEMENAME' ) );
next_post_link( '<div class="nav-next">' . get_the_post_thumbnail() . '%link</div>', _x( '%title', 'Next post link', 'THEMENAME' ) );
?>
</div><!-- .nav-links -->
</nav><!-- .navigation -->
<?php
}