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.
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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
| <?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
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
Another Premium plugins
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!
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.
No comments:
Post a Comment