Featured images are very important part of modern WordPress themes and modern WordPress sites. Post Thumbnails was initially introduce in WordPress Version Version 2.9 which was changed to Featured Images with Version 3.0.

Sometimes you publish the post & then you realize that the featured post is not set for the article, so again you need to go back and update the post.

What is the solution?

Auto Post Thumbnail Plugin

The best solution is to do something which will  automatically set the featured image in WordPress sites.

How to automatically set the featured image in WordPress?

We have a few ways to automatically set the featured image in WordPress based sites.

1. Auto Post Thumbnail

Auto Post Thumbnail is a plugin which will automatically set the featured image in WordPress by generating post thumbnail from the first image in post or any custom post type only if Post Thumbnail is not set.

If the post thumbnail is already present, the plugin will do nothing. If you don’t want a post thumbnail for some post with images, just add a custom field skip_post_thumb to the post and the plugin will restrain itself from generating post thumbnail.

Download Plugin

2. Modify Function.php

Another way to automatically set the featured image in WordPress sites is by modifying the function.php file of your theme.

Add this snippet to your theme’s functions.php file.

<?php
function autoset_featured() {
          global $post;
          $already_has_thumb = has_post_thumbnail($post->ID);
              if (!$already_has_thumb)  {
              $attached_image = get_children( "post_parent=$post->ID&post_type=attachment&post_mime_type=image&numberposts=1" );
                          if ($attached_image) {
                                foreach ($attached_image as $attachment_id => $attachment) {
                                set_post_thumbnail($post->ID, $attachment_id);
                                }
                           }
                        }
      }
add_action('the_post', 'autoset_featured');
add_action('save_post', 'autoset_featured');
add_action('draft_to_publish', 'autoset_featured');
add_action('new_to_publish', 'autoset_featured');
add_action('pending_to_publish', 'autoset_featured');
add_action('future_to_publish', 'autoset_featured');
?>

Code courtesy  wp-snippet.com

Don’t forget to backup our database before changing the function.php file of your theme.

Check few other useful tutorials, plugins & themes on indexwp. Keep your self updated with all the news from WordPress community by subscribing to indexwp

Automatically Set The Featured Image in WordPress
IndexWP Ratings92%
User Ratings87%
Usability95%
91%Overall Score
Reader Rating: (1 Vote)
99%

3 Responses

Leave a Reply

Your email address will not be published.

Grow Your Traffic To 40,000/Month

Learn the 6 plugins we used to grow our own traffic from 0 to 40,000 a month within a year.

We never share your E Mail ID with anyone

Grow Your Traffic To 40,000/Month

Learn the 6 plugins we used to grow our own traffic from 0 to 40,000 a month within a year.

We never share your E Mail ID with anyone