In this post i’ll show you how to display a copy of your featured image before your previous & next single post navigation links.
Update : This new tutorial includes a better solution which also includes CSS for Media Queries and a placeholder image displayed when no featured image is added.
And here’s an example of what the code does:
PHP Code
Please copy ALL the code from the view raw link and paste it at the end of your child themes functions.php file using a text editor like Notepad++.
The code uses a genesis hook however you can use any WordPress or theme specific hook otherwise you’ll need to filter the content to add the links after your content on single posts for themes which don’t include action hooks.
The code includes the $in_same_cat parameter which means all single posts within each category are linked together. If you don’t want all posts in all categories linked together, change the value from TRUE to FALSE.
Functions the code uses:
- next_post_link
- previous_post_link
- get_next_post
- get_previous_post
- get_the_post_thumbnail
Featured Image Sizes
The above code uses the native medium image size which you can change in Settings > Media > Image Sizes.
If you want to use a different size as to what these settings include, you can add a new image size to your child themes functions file and regenerate thumbnails.
add_image_size( 'image-name', 200, 100, TRUE );
If you change any of the native image sizes, you will also need to regenerate thumbnails if you want to use the new image size for your previous and next post nav links.
CSS Code
The CSS code includes a hover effect for your featured images and a class for both the previous and next post nav links.
What This Code Generates
Was This Tutorial Helpful?