-
-
Save unRARed/72e434fbaf4390a5f1a2 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 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( str_replace(get_home_url().'/', '', $image[0]) ) ) { | |
// Replace the image source with a placeholder at the proper dimensions. | |
$image[0] = "http://placehold.it/{$image[1]}x{$image[2]}/ffd602/000000"; | |
} | |
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