Setting default featured image using wordpress plugin

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

How to show featured image in wordpress admin panel list

Featured images are very important feature of wordpress. Many blogger use the featured images on top. With watching the featured images user got idea about blog post or your article. Some time we miss to upload the featured image.

How to show featured image in wordpress admin panel list

But in post list cannot able to see the featured image in admin panel.

I found very nice wordpress plugin which is helpful to show the featured image in admin panel.

Featured Image Column – Adds a column to the edit screen with the featured image if it exists.

This plugin has no options. It simply adds a column before the title (far left) the show’s the posts featured image if it’s supported and/or exists.

Add a defualt image simply by filtering you own image in. Use featured_image_column_default_image or filter your own CSS by using featured_image_column_css.

Add support for a custom default image

How to show featured image in admin panel list - in post list - for wordpress
How to show featured image in admin panel list – in post list – for wordpress
function my_custom_featured_image_column_image( $image ) {
    if ( !has_post_thumbnail() )
        return trailingslashit( get_stylesheet_directory_uri() ) . 'images/featured-image.png';
}
add_filter( 'featured_image_column_default_image', 'my_custom_featured_image_column_image' );

Add your own CSS to change the size of the image.

/**
 * @use '.featured-image.column-featured-image img {}'
 */
function my_custom_featured_image_css() {
    return trailingslashit( get_stylesheet_directory_uri() ) . 'css/featured-image.css'; //URL to your css
}
add_filter( 'featured_image_column_css', 'my_custom_featured_image_css' );

I found this plugin is really helpful to me. Using this plugin I can easily check the featured image.

How to set post first image as featured image automatically

So using or choosing the image as featured image for post is another manual work we need to do. Info about. how to set post first image as featured image. We have SQL query for this.

From wordpress 3.0 version wordpress launched the feature called featured image. Many new wordpress themes are compatible with new wordpress version. So using or choosing the image as featured image for post is another manual work we need to do.

Many old wordpress website holder or blogger is having issue with this functionality. What they want is when they create the post they haven’t set the featured image, but they would like the featured image to default to the image that has been included in the post.

Some wordpress always use the first image as featured image but old post was not updated with featured image. They need to do manual work to set the featured image. I also faced same issue.

After doing some R&D I found the solution. If you want to set the your posts first image as featured image then use my following code.

For using the code you need to open your mysql database command prompt or phpmysqladmin program and select your wordpress database and execute the following query in that.

insert into wp_postmeta (meta_value, meta_key, post_id) select DISTINCT(ID), post_type , post_parent from wp_psts where post_type= 'attachment' and post_parent !=0 and post_status='inherit';<br /><br />update wp_postmeta set meta_key = '_thumbnail_id' where meta_key='attachment'

Using above sql query you will be able to set the featured image to your old and new post from post content. If you are having any issues with using this sql then write to me.

How to set post first image as featured image automatically
How to set post first image as featured image automatically