Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author keesiemeijer

    (@keesiemeijer)

    Hi hwuser

    Try it with this in your (child) theme’s functions.php file:

    
    add_filter( 'related_posts_by_taxonomy_post_thumbnail_link', 'rpbt_related_post_fallback_image', 10, 4 );
     
    function rpbt_related_post_fallback_image( $image, $attr, $related, $args ) {
       	$featured = get_the_post_thumbnail( $related, $args['size'], $attr['describedby'] );
     
        return "<a href='{$attr['permalink']}'>{$image}</a>";
    }

    btw:
    consider creating a child theme instead of editing your theme directly – if you upgrade the theme all your modifications will be lost. Or create a plugin with the code above.

    • This reply was modified 6 years, 1 month ago by keesiemeijer.
    Thread Starter hwuser

    (@hwuser)

    Hello, many thanks for your quick reply. But the code does not do anything. The same image keeps appearing in all the related posts…

    Plugin Author keesiemeijer

    (@keesiemeijer)

    Oh, I see now that code indeed does nothing ??

    Try it with this

    
    add_filter( 'related_posts_by_taxonomy_post_thumbnail_link', 'rpbt_related_post_fallback_image', 10, 4 );
     
    function rpbt_related_post_fallback_image( $image, $attr, $related, $args ) {
       	$featured = get_the_post_thumbnail( $related, $args['size'], $attr['describedby'] );
     
        return "<a href='{$attr['permalink']}'>{$featured}</a>";
    }
    

    I think the reason the post thumbnails are all the same is because the featured image from url plugin filters the WordPress post thumbnail output. My plugin (at this moment) doesn’t use the get_the_post_thumbnail() function to get the post thumbnail image. I hope this makes sense.

    Thread Starter hwuser

    (@hwuser)

    Yeeeeeeees!!! Already works perfectly!!!!
    Thank you for the speed in finding a solution.
    Thank you very very much !!!!

    Plugin Author keesiemeijer

    (@keesiemeijer)

    You’re welcome ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Same image in the thumbnails’ is closed to new replies.