WordPress.org

Ready to get started?Download WordPress

Plugin Directory

Default featured image

Add a default featured image to the media settings page

My chosen featured image doesn't show, why isn't it working?

This plugin can't guarantee that it works. That depends on the themes. Still I want to know if it fails, so contact me

Which functions can I use to display the featured image?

The plugin uses the default WordPress functions the_post_thumbnail or get_the_post_thumbnail. has_post_thumbnail will always return true. get_post_thumbnail_id will return the ID set on the post or the DFI you set.

Can I exclude a page or give it a different image?

Yes you can by using the buildin dfi_thumbnail_id filter. It will give you the post id which you can use to check against.

Don't use a featured image on page 23

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

Use a different image for some categories

The example below only works if the post has 'animals' as a category. Asigning just 'cats' won't work To do that just don't nest the if

function dfi_category ( $dfi_id, $post_id ) {
  // all which have 'animals' as a category
  if ( has_category( 'animals', $post_id ) ) {

    //sub category
    if ( has_category( 'cats', $post_id ) ) {
      return 7; // cats img
    } else if has_category( 'dogs', $post_id ) {
      return 8; // dogs img
    }

    return 6; // default animals picture
  }
  return $dfi_id; // the original featured image id
}
add_filter( 'dfi_thumbnail_id', 'dfi_category', 10, 2 );

Different image for the posttype 'wiki'

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

Can I change the HTML of the image returned?

yes you can with the filter dfi_thumbnail_html.

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 );
}
add_filter( 'dfi_thumbnail_html', 'dfi_add_class', 10, 5 );

Requires: 3.5 or higher
Compatible up to: 3.8.3
Last Updated: 2014-2-4
Downloads: 14,617

Ratings

4 stars
4.8 out of 5 stars

Support

0 of 4 support threads in the last two months have been resolved.

Got something to say? Need help?

Compatibility

+
=
Not enough data

0 people say it works.
0 people say it's broken.

50,4,2 100,1,1
100,2,2 100,1,1
100,1,1
100,1,1
50,2,1
100,1,1
50,2,1
100,1,1 100,2,2
100,1,1