Last active
April 8, 2016 00:47
-
-
Save jeherve/6992527 to your computer and use it in GitHub Desktop.
[Jetpack] Add a default fallback image if no image can be found in a post
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 | |
/* | |
* Plugin Name: Jetpack default image | |
* Plugin URI: http://wordpress.org/extend/plugins/ | |
* Description: Add a default fallback image if no image can be found in a post | |
* Author: Jeremy Herve | |
* Version: 1.0 | |
* Author URI: http://jeremyherve.com | |
* License: GPL2+ | |
*/ | |
function jeherve_custom_image( $media, $post_id, $args ) { | |
if ( empty( $media ) ) { | |
$permalink = get_permalink( $post_id ); | |
$url = apply_filters( 'jetpack_photon_url', 'YOUR_LOGO_IMG_URL' ); | |
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