Skip to content

Instantly share code, notes, and snippets.

@rodgtr1
Created April 12, 2018 02:23
Show Gist options
  • Save rodgtr1/34da45a6f818ca7efcedb976285a9d1c to your computer and use it in GitHub Desktop.
Save rodgtr1/34da45a6f818ca7efcedb976285a9d1c to your computer and use it in GitHub Desktop.
Create Default Fallback Image For Jetpack Related Posts
function jp_custom_image( $media, $post_id, $args ) {
if ( $media ) {
return $media;
} else {
$permalink = get_permalink( $post_id );
$url = apply_filters( 'jetpack_photon_url', 'https://example.com/wp-content/uploads/2017/07/example-image.jpg' );
return array( array(
'type' => 'image',
'from' => 'custom_fallback',
'src' => esc_url( $url ),
'href' => $permalink,
) );
}
}
add_filter( 'jetpack_images_get_images', 'jp_custom_image', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment