Last active
December 14, 2015 22:46
-
-
Save CurtisL/ccac465e52061383c88b to your computer and use it in GitHub Desktop.
Wordpress filter to replace 404'd images with a placeholder, Good for when you're working locally but don't want to copy down the whole uploads directory.
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 | |
/** | |
* Dev Helper for 404'd Images | |
*/ | |
function placehold_404( $image ) { | |
if ( file_exists( ABSPATH . str_replace(get_home_url().'/', '', $image[0]) ) ) { | |
return $image; | |
} | |
// Replace the image source with a placeholder at the proper dimensions. | |
$image[0] = "http://placehold.it/{$image[1]}x{$image[2]}/FF6600/FFFFFF"; | |
return $image; | |
} | |
add_filter( 'wp_get_attachment_image_src', 'placehold_404' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Breaks in WP 4.4 due to the addition of image srcset