Skip to content

Instantly share code, notes, and snippets.

@chrisaldrich
Last active October 4, 2020 01:50
Show Gist options
  • Save chrisaldrich/d3b63ca50964328bd72b876a748866d2 to your computer and use it in GitHub Desktop.
Save chrisaldrich/d3b63ca50964328bd72b876a748866d2 to your computer and use it in GitHub Desktop.
Adding default image to the Jetpack Related Posts if none exists
/* Adding default image to the Jetpack Related Posts if none exists */
function jeherve_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/photo.jpg' );
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 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment