How to automatically assign a featured image to your posts in WordPress
Up until recently, whenever I embedded a video into a post in WordPress. I would take a screenshot of the video, crop out the video player and use the image as the preview featured image for the post. Then I started to think “I wonder if there is a way that I could hook into the API for youtube and return the thumbnail they generate on their end?”. Which I then followed that up with another thought “I bet there is a plugin that is already doing this!”.
How it Works (in a nutshell)
According to the plugin description:
Video Thumbnails makes it easy to automatically display video thumbnails in your template. When you publish a post, this plugin will find the first video embedded and retrieve a thumbnail for you. Thumbnails can be saved to your media library and set as a featured image automatically. There’s even support for custom post types and custom fields!
Use Case 1: Applying thumbnails to existing posts
I had a site that already had posts with video links embedded into the posts. One of the features I did not expect but was pleasantly surprised. Was the ability to mass scan and apply featured images to existing posts.
Use Case 2: Video Embed in a 3rd party shortcode plugin
I use a third party plugin for generating Foundation 5 shortcodes and part of the shortcode offerings are responsive videos called “Flex Video” It essentially wraps your element with markup and the proper CSS to ensure your videos are responsive. In the shortcode, you pass your video URL and I was hesitant to see if the Video Thumbnail plugin would still be able to parse properly and do its job. Happy to say, the answer is Yes! I haven’t tested thoroughly with many other video embed plugins but would love to hear your experiences in the comments.
Testing and Debugging
Another great feature was the ability to test and debug various providers, markups and the ability retrieve the remote image and save it to your Media Library
There is also a Pro version of the plugin which I’m sure has some worthwhile features. But the free one out of the box has really impressed.