If I create a post that has an embedded YouTube video in it (so all I do is paste the YouTube URL into the post and let WordPress automatically embed it for me), is there a way to have the thumbnail image of the video set as the post’s featured image?
Leave a Reply
You must be logged in to post a comment.
Not natively. You’d have to write some code to make it happen – there’s a nice pastebin function that provide the necessary code to do it.
Edit (12/19/2011):
Yep here’s how you can do this programmatically. Add the following two functions to your functions.php file and you should be good to go. The code has been commented to explain what’s happening, but here’s a high level of what to expect:
You must…
The code will…
Note that if you include multiple URLs in your post, you’ll need to modify the code to properly find the YouTube URL. This can be done by iterating through the
$attachments
collection and sniffing out what URL’s look like a YouTube URL.One thing to note is that this assumes that your post has no post thumbnail and will not fire once a post thumbnail is set.
Secondly, if you remove the post thumbnail and then attach an image to this post using the media uploader, the most recent image will be used.