This code displays the same image for all related posts featured images so the image you add as a featured image on single posts isn’t displayed for related posts.
Here’s an example of what Jetpacks related posts displays before adding the code:
And here’s an example showing how each related post uses the same image.
Change the path to your image in the code and add to your child themes functions file:
function jeherve_custom_image( $post_id, $args ) {
$permalink = get_permalink( $post_id );
$url = apply_filters( 'jetpack_photon_url', 'http://example.com/wp-content/uploads/2200/10/wpsites.png' );
return array( array(
'type' => 'image',
'from' => 'custom_fallback',
'src' => esc_url( $url ),
'href' => $permalink,
) );
}
add_filter( 'jetpack_images_get_images', 'jeherve_custom_image', 10, 2 );
You can also add a default image to related posts when none added.
Leave a Reply