A function to add default images for themes
|Reported by:||F J Kaiser||Owned by:|
Description (last modified by scribu)
Adding default images to themes is not an easy task. They have to play nicely with different image sizes that are built-in and/or added via add_image_size();. If they don't, then they will simply break the layout or won't change with user changes. Sadly we can't simply use most of the core media/image functions as those functions check if the image is an attachment image and - if not - abort.
So I want to introduce wp_default_img();. It works with an input array of attributes and offers two filters (wp_default_img_attr & wp_default_img). So setting up default images is as easy as using a filter (if the theme developer isn't satisfied with the functions default args) and finally just adding
// functions.php during init: add_image_size( 'default_img', 80, 80, true ); // Inside some template $placeholder = get_site_url( null, 'your_path' ).'/some_img.jpg'; echo wp_default_img( array( 'url' => $placeholder, 'size' => 'default_img' ) );
The function also cares about cropping images if 4th argument set to true when registering the size using add_image_size();.