sandywp / plugins / default-featured-image

Default Featured Image

4.8 out of 5 stars. 4.8 68 reviews

Add a Default Featured Image for all posts & pages.

Launch a sandbox with this plugin → No signup.
Ready in seconds.

v1.8.2 60,000+ installs WP 6.2+ PHP 7.4+

your-sandbox.sandywp.com/wp-admin
Default Featured Image running inside a SandyWP sandbox

What you get inside

2 screens
  • The setting on the media page

  • The media manager will start with the current selected image

About this plugin

Add a default featured image to the media settings page. This featured image will show up if no featured image is set. Simple as that.

Take a look at FAQ for the basic questions.
Feel free to contact me on the forum or on the github repository.

Questions

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.

  • Switch themes. Most of the time the theme does something weird.
  • Are you using the Core WordPress functions to get the image? (see the FAQ below this one).
  • Do normal feature images work?
  • Might it be hidden via css? DFI images have an extra default-featured-img class added to them.

Still having problems? I want to know if it fails, so contact me

Which functions can I use to display the featured image?

There are no new functions, all core WordPress functions can be used.

Can I set a different image for a custom post type?

Yes, the following code will set a different image.

add_filter( 'dfi_thumbnail_id', 'dfi_posttype_book', 10, 2 );
function dfi_posttype_book( $dfi_id, $post_id ) {
    $post = get_post( $post_id );
    if ( 'book' === $post->post_type ) {
        return 31; // the image id for the book post type.
    }

    return $dfi_id; // the original featured image id.
}

Can I set different images per category?

Yes, the following snippet will set different images based on the category.

add_filter( 'dfi_thumbnail_id', 'dfi_category', 10, 2 );
function dfi_category( $dfi_id, $post_id ) {
    // Set a different image for posts that have the 'cats' category set.
    // This will trigger first, if multiple categories have been set.
    if ( has_category( 'cats', $post_id ) ) {
        return 7; // cats img id.
    }
    // Set a different image for posts that have the 'cats' category set.
    if ( has_category( 'dogs', $post_id ) ) {
        return 8; // dogs img id.
    }

    return $dfi_id; // the original featured image id.
}

Can I change the HTML of the default featured image?

When a Default Featured Image is used it will already add an extra class default-featured-img.
This can be used for styling.

If you need more you can change the whole HTML with the filter dfi_thumbnail_html.

add_filter( 'dfi_thumbnail_html', 'dfi_add_class', 10, 5 );
function dfi_add_class( $html, $post_id, $default_thumbnail_id, $size, $attr ) {
    // Add a class to the existing class list.
    $attr['class'] .= ' my-class';

    return wp_get_attachment_image( $default_thumbnail_id, $size, false, $attr );
}

Can I exclude one page from having a Default Featured Image?

The following code will exclude the post/page with ID 23.

add_filter( 'dfi_thumbnail_id', 'dfi_skip_page', 10, 2 );
function dfi_skip_page( $dfi_id, $post_id ) {
    if ( $post_id == 23 ) {
        return 0; // invalid id.
    }

    return $dfi_id; // the original featured image id.
}

4.8

68 reviews

  • 5 ★ 63
  • 4 ★ 2
  • 3 ★ 1
  • 2 ★ 1
  • 1 ★ 1

Ratings come from WordPress.org. SandyWP does not collect its own reviews.

sandywp / also on the shelf

Try another plugin

  • Imsanity

    4.9 · 200K+ installs

    Automatically resizes huge image uploads. Are contributors uploading huge photos? Tired of manually resizing your images?…

  • Firelight Lightbox

    4.8 · 200K+ installs

    Formerly Easy Fancybox. The most popular WordPress lightbox plugin. Simple, fast, and responsive. Opens images, videos, PDFs, and…

  • Responsive Lightbox & Gallery

    4.9 · 100K+ installs

    The most popular lightbox plugin and responsive gallery builder for WordPress.

Spin up a real WordPress site in seconds.

Test plugins, build a demo, hand a client a link — then squash it and start again. No local setup, no Docker.