Skip to content

Instantly share code, notes, and snippets.

@jeherve
Last active April 8, 2016 00:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jeherve/6992527 to your computer and use it in GitHub Desktop.
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
<?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