Skip to content

Instantly share code, notes, and snippets.

@unRARed
Forked from CurtisL/placehold-404.php
Last active November 4, 2015 21:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unRARed/72e434fbaf4390a5f1a2 to your computer and use it in GitHub Desktop.
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.
<?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