youthumb (by YCB)

youtube thumbnailerYouThumb is a WordPress plugin that extends the functionality of a previous thumbnail generator. It automatically adds a thumbnail of the first YouTube video embedded in the post.


  • It automatically adds an “entry-preview” custom field to posts that are published and have a youtube embed code, and it fills it with a link to the thumbnail.
    Future Work:

  • Seamlessly integrate with the MS auto-thumbnail-generator plugin to allow for different key titles than “entry-preview”.
Plugin Name: YouThumb
Plugin URI:
Description: Automatically detects youtube embeds in posts before they are added, and sets the "entry-preview" field to link to a thumbnail of it.
Author: Guru Khalsa
Author URI:
if (!class_exists("YouThumb")) {
class YouThumb {

private $flag = False;
private $ytid = “”;
private $yt_thumb = “”;
private $uploaded_url=””;

function YouThumb() { //constructor


function detectEmbed($content){
#gets the first youtube ID it sees that follows the pattern …/v/(youtube ID)&…
if(preg_match(‘#/v/(.+?)&#’, $content, $matches)){
#sets ytid to the matched id, and sets the flag to true
$this->ytid = $matches[1];
$this->flag = True;

return $content;

function uploadThumbnail($post_ID){
#uploads and returns <img src=”blah/blah/blah/the_new_url.jpg” />
$yt_thumbnail_html = media_sideload_image($this->yt_thumb,$post_ID);

#get just the URL
if(preg_match(“#src='(.+?)’#”, $yt_thumbnail_html, $matches)){
$this->uploaded_url = $matches[1];

function getYtThumb(){
$this->yt_thumb = “”.$this->ytid.”/2.jpg”;

function addThumbnail($post_ID){

update_post_meta($post_ID, ‘entry-preview’, $this->uploaded_url);



} //End Class YouThumb

if (class_exists(“YouThumb”)) {
$ns_youthumb = new YouThumb();

//Actions and Filters
if (isset($ns_youthumb)) {
add_filter(‘content_save_pre’, array(&$ns_youthumb, ‘detectEmbed’));

add_action(‘publish_post’, array(&$ns_youthumb, ‘addThumbnail’));


Download here.

Leave a Reply

Your email address will not be published. Required fields are marked *