Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

Display featured image’s thumbnail on previous/next posts

  • Greetings:

    To improve user engagement on the website, I’d like to display featured image’s thumbnail along with previous/next post links at the bottom of every post.

    Please guide how to accomplish this using the GP Premium theme.

    Thank you.

  • Hi Sam,

    This article should be helpful regarding this: https://docs.generatepress.com/article/block-element-post-navigation/

  • Do I need to be using block editor for this?

  • Please note that the website still uses the Classic Editor and I intend to keep it that way.

    Please suggest a resolution keeping above in mind.

    Thanks.

  • Yes, you would need to use the Block Editor.

    Unfortunately, without using the Block Editor, you’ll need a custom code. This would be out of our scope of support though.

  • Thanks for your response.

    I did some research. Will the code listed on following link work if added to functions.php?

    Link: https://gist.github.com/generatepress/dc79fa83d8706f19365aa07ddd141cd3

  • Hi there,

    You can give it a try.

    The function doesn’t specify the size of the image though, you might need extra CSS or change the code a bit to add size attribute.

    For example, you can change these 2 lines:

    $prevThumbnail = isset( $prevPost ) ? get_the_post_thumbnail( $prevPost->ID ) : '';
    $nextThumbnail = isset( $nextPost ) ? get_the_post_thumbnail( $nextPost->ID ) : '';

    to:

    $prevThumbnail = isset( $prevPost ) ? get_the_post_thumbnail( $prevPost->ID, array( 300, 200 ) ) : '';
    $nextThumbnail = isset( $nextPost ) ? get_the_post_thumbnail( $nextPost->ID, array( 300, 200 ) ) : '';

    So the output images will be 300px * 200px, feel free to change the values 🙂

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.