WordPress: Default Image for Jetpack Related Posts

<?php function jeherve_custom_image( $media, $post_id, $args ) { if ( $media ) { return $media; } else { $permalink = get_permalink( $post_id ); $url = apply_filters( 'jetpack_photon_url', 'URL_of_image' ); return array( array( 'type' => 'image', 'from' => 'custom_fallback', 'src' => esc_url( $url ), 'href' => $permalink, ) ); } } add_filter( 'jetpack_images_get_images', 'jeherve_custom_image', 10, 3 ); ?>
You can define a default image that will be used with all Related Posts that do not include an image in the post content.
Add this code snippet to your theme’s functions.php file, or in a functionality plugin.

It’s worth noting that the fallback image has to be larger than 200 x 200px, as per Facebook requirements. If your image is smaller, Facebook will ignore it.

Further explanation: https://jetpack.com/2013/10/15/add-a-default-fallback-image-if-no-image/

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.