Skip to content

Instantly share code, notes, and snippets.

@dartiss
Created November 15, 2017 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dartiss/c3b061b9e8346305423305fa8813a7d5 to your computer and use it in GitHub Desktop.
Save dartiss/c3b061b9e8346305423305fa8813a7d5 to your computer and use it in GitHub Desktop.
Add a Default Image to Jetpack Related Posts
<?php
function jrp_custom_image( $media, $post_id, $args ) {
if ( $media ) {
return $media;
} else {
$permalink = get_permalink( $post_id );
$url = apply_filters( 'jetpack_photon_url', '[image url]' );
return array( array(
'type' => 'image',
'from' => 'custom_fallback',
'src' => esc_url( $url ),
'href' => $permalink,
) );
}
}
add_filter( 'jetpack_images_get_images', 'jrp_custom_image', 10, 3 );
?>
@dartiss
Copy link
Author

dartiss commented Nov 15, 2017

Due to some changes to my site a number of posts no longer have featured images and may not include an image either. This code allows you to specify an image that will appear as a default in such situations.

Add to your theme's functions.php and replace [image url] with the full URL to the default image.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment