Skip to content

Instantly share code, notes, and snippets.

@anunay
Last active December 29, 2015 01:39
Show Gist options
  • Save anunay/7594625 to your computer and use it in GitHub Desktop.
Save anunay/7594625 to your computer and use it in GitHub Desktop.
Wordpress Youtube Thumbnail
<?php
function wordpress_youtube_thumbnail($content){
preg_match("/v\/([^*]+)/i", $content, $matches);
$matches[1] = preg_replace("/\?/","&",$matches[1]);
if($matches[1]=="" || empty($matches[1])){
preg_match("/watch\?v=([^*]+)/i", $content, $matches);
$matches[1] = preg_replace("/\?/","&",$matches[1]);
}
$images = explode("&",$matches[1]);
//http://img.youtube.com/vi/bQVoAWSP7k4/1.jpg
if($images[0] && isset($images[0])){
return '<img class="alignleft" src="http://img.youtube.com/vi/' . substr($images[0],0,11) . '/2.jpg" alt="' . $thumb->post_title . '" ' . $add . '>';
}else{
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment