Created
November 15, 2017 16:28
-
-
Save dartiss/c3b061b9e8346305423305fa8813a7d5 to your computer and use it in GitHub Desktop.
Add a Default Image to Jetpack Related Posts
This file contains hidden or 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
<?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 ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.