How to automatically set featured image in WordPress

envato

If you don not like manually picking featured image for every single post of your blog, so here is a simple tip to help you make your WordPress automatically set featured image by grabbing the first image of the post.

set-featured-image-in-wordpress

Featured images are very important part of modern WordPress themes. This image is often times meant to be an overview, or advertising for the post. In this article, we will show you how automatically set the first image of post as the featured image.

I have a 2 ways to automatically set the featured image in WordPress

1. Add this snippet to functions.php file in your current theme:

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

2. Auto Post Thumbnail WordPress Plugin

 

auto-post-thumbnail-wordpress-plugin

Automatically generate the Post Thumbnail (Featured Thumbnail) from the first image in post or any custom post type only if Post Thumbnail is not set

 

DOWNLOAD

Another Premium plugins

Image Fetcher – Featured Image Convertor

 

Image Fetcher - Featured Image Convertor

Image Fetcher is a simple plugin that automatically converts image link to the featured image easily and quickly! Basically you can start converting by just one click!

DOWNLOAD

Auto Post Thumbnail PRO

 

Auto Post Thumbnail PRO

Auto Post Thumbnail PRO is a plugin to generate Featured Image (AKA Post Thumbnail) from first image in a post or any custom post type content. The plugin will also create thumbnails from several popular Video services if it finds a Video embedded in the post.

DOWNLOAD

Leave a Reply

Your email address will not be published.

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=""> <s> <strike> <strong>