Many people using featured images in there blog or sites. Setting default featured image using wordpress plugin for every post is not possible for some times so creating the one default image and set that default image for all the posts is really good idea. Some times If you not have the default image then it is possible to break your wordpress theme or it does not look nice without featured image. In this article I will show you how to Setting default featured image using wordpress plugin.

 

Setting default featured image using wordpress plugin

Setting default featured image using wordpress plugin for post is not possible for some times so creating default image, for all posts is really good idea.

But still you want to set the default featured image using following wordpress plugin.

Default featured image
http://wordpress.org/plugins/default-featured-image/

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.

For exceptions and to see which functions to use see the FAQ.
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 exclude all kinds of things with the conditional tags. A few examples which you can paste in your functions.php

Dont use a featured image on page 5


function dfi_skip_page( $dfi_id ) {
 if ( is_single( 5 ) || get_the_ID() == 5 ) {
 return 0; // invalid id
 }
 return $dfi_id; // the original featured image id
 }
 add_filter('dfi_thumbnail_id', 'dfi_skip_page' );

Use a different image on the “book” posttype. The ID of the image is 12


function dfi_posttype_book( $dfi_id ) {
 if ( is_singular( 'book' ) || get_post_type() == 'book' ) {
 return 12; // the image id
 }
 return $dfi_id; // the original featured image id
 }
 add_filter('dfi_thumbnail_id', 'dfi_posttype_book' );

Use a different image on certain categories


function dfi_category( $dfi_id ) {
 if ( has_category( 'category-slug' ) ) {
 return 13; // the image id
 } else if ( has_category( 'other_category' ) ) {
 return 14; // the image id
 }
 return $dfi_id; // the original featured image id
 }
 add_filter('dfi_thumbnail_id', 'dfi_category' );

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 );

First thing you need to do is install and activate the Default Featured Image plugin. Upon activation, the plugin adds an option under Setttings » Media to choose a default image.

Setting default featured image using wordpress plugin

Setting default featured image using wordpress plugin

Written by Purab Kharat

I Purab am from Pune. I worked as WordPress and Drupal Architect and consultant. I worked on many technologies like Wordpress, Drupal, Ruby on Rails, Flex, PHP, jQuery etc... Senior Technical Lead at Smartsourcing Global Pvt Ltd in Princeton, NJ, USA.I contributor of many wordpress plugins and Drupal Modules. I am core developer of Drupal.Connect to purab on LinkedIn or Follow @purab on Twitter or Follow me on Google+ or Write Mail to purabdk@gmail.com or Chat with me on Skype : purabdk

Leave a Comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>