If you have thumbnails for your blog theme and you have no images in the post, but you have YouTube Videos, then you can pull the YouTube Video Thumbnail using this PHP function.
function kish_update_video_thumbnail($youtubeurl, $postid) {
if(strlen($youtubeurl)) {
//$pattern="/[\?&]v=([^&#]*)/";
$pattern="/http://www.youtube.com/v/([w-]{11})/";
preg_match($pattern, $youtubeurl, $matches);
$thumb="http://img.youtube.com/vi/".$matches[1]."/0.jpg";
update_post_meta($postid, 'video_thumb', $thumb);
}
}
The commented pattern can be used if you are using the video URL. This will update the post_meta with the thumb URL
Related posts:
- How to extract the title and meta description using Simple HTML Dom Parser Simple HTML Dom is an excellent script in PHP to...
- Installing Kish Twit Pro – Quick Guide with Video Installation of Kish Twit Pro is very simple like a...
- How to do a post using Kish Multi Pro? Writing a blog post is made very simple when you...
- Updating post custom fields using XMLRPC – WordPress Updating the custom data of a post which can be...
- WordPress has enabled Phone Blogging We have been blogging using Windows Live Writer, Ecto,...
You should have got the notification to upgrade your WordPress Installation. Most of us do it instan →
There are many blogging softwares like Joomla, WordPress, Drupal, etc, but I would suggest you to go →
I always wait for beta releases and love to test it and try to know about the new features, and also →
{ 4 comments… read them below or add one }
Thanks for the code…How would you then call this function to display the thumb in a portfolio page?
You can call this function where ever you want and have an YouTube URL
Great code. but i have a question, do you can show or maybe suggest how can i save the thumb into o folder on my website?
You can use the copy function to do that http://php.net/manual/en/function.copy.php