Last active
October 4, 2020 01:50
-
-
Save chrisaldrich/d3b63ca50964328bd72b876a748866d2 to your computer and use it in GitHub Desktop.
Adding default image to the Jetpack Related Posts if none exists
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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