Set a default featured image for posts, pages, and custom post types with an option to enable or disable automatic application.
Defaultify Featured Image allows WordPress site administrators to specify a default featured image that will be used when a post doesn’t have one. The plugin now includes an option to enable or disable the automatic application of default images.
Where can I get support?
For plugin support, feature requests, or bug reports, please contact us at navneetkrkashyap@gmail.com. We typically respond within 24-48 hours during business days.
You can also:
* Search existing support topics in the WordPress.org support forum
* Report bugs or suggest features via email
When contacting support, please include:
* Your WordPress version
* Your theme name and version
* A detailed description of the issue
* Steps to reproduce the problem (if applicable)
My chosen featured image doesn’t show, why isn’t it working?
This plugin works out of the box for most cases, but not always. If it doesn’t work you can try the following things:
- Make sure the “Automatically apply default image” checkbox is enabled
- Switch themes. Some themes may handle featured images in non-standard ways
- Ensure you’re using the Core WordPress functions to get the image
- Check if normal featured images work on your site
- The image might be hidden via CSS. Default images have an extra
default-featured-img class added to them
Can I set a different image for a custom post type?
Yes, you can use the following code snippet:
`php
add_filter( ‘wpdfi_thumbnail_id’, ‘wpdfi_posttype_book’, 10, 2 );
function wpdfi_posttype_book( $wpdfi_id, $post_id ) {
$post = get_post( $post_id );
if ( ‘book’ === $post->post_type ) {
return 31; // the image id for the book post type
}
return $wpdfi_id; // the original featured image id
}
`
Can I set different images per category?
Yes, here’s how you can set different images based on categories:
`php
add_filter( ‘wpdfi_thumbnail_id’, ‘wpdfi_category’, 10, 2 );
function wpdfi_category( $wpdfi_id, $post_id ) {
// Set a different image for posts that have the ‘cats’ category
if ( has_category( ‘cats’, $post_id ) ) {
return 7; // cats image id
}
// Set a different image for posts that have the ‘dogs’ category
if ( has_category( ‘dogs’, $post_id ) ) {
return 8; // dogs image id
}
return $wpdfi_id; // the original featured image id
}
`
Can I change the HTML of the default featured image?
When a default featured image is used, an extra class default-featured-img is added automatically. If you need more customization, you can use the wpdfi_thumbnail_html filter:
`php
add_filter( ‘wpdfi_thumbnail_html’, ‘wpdfi_add_class’, 10, 5 );
function wpdfi_add_class( $html, $post_id, $default_thumbnail_id, $size, $attr ) {
// Add a class to the existing class list
$attr[‘class’] .= ‘ my-custom-class’;
return wp_get_attachment_image( $default_thumbnail_id, $size, false, $attr );
}
`
Can I exclude specific pages from having a default featured image?
Yes, here’s how to exclude a specific post or page:
`php
add_filter( ‘wpdfi_thumbnail_id’, ‘wpdfi_skip_page’, 10, 2 );
function wpdfi_skip_page( $wpdfi_id, $post_id ) {
if ( $post_id == 23 ) {
return 0; // invalid id – no image will be applied
}
return $wpdfi_id; // the original featured image id
}
`
How can I control when the default image is applied?
You can use the checkbox in the media settings page to enable or disable automatic application of the default image. When disabled, the default image will not be automatically applied to posts without a featured image.