auto-post-thumbnail hack to use the youtube image when no other images
-
This is a quick and dirty hack to force the auto-post-thumbnail to use the first available youtube image for a thumbnail if no other image is available in the post and it contains almost any kind of youtube embed.
Find
// Get all images from post's body preg_match_all('/<\s*img [^\>]*src\s*=\s*[\""\']?([^\""\'>]*)/i', $post[0]->post_content, $matches);
and add immediately afterwards
if (empty($matches[0])) { preg_match('%(?:youtube\.com/(?:user/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $post[0]->post_content, $match); if (!empty($match[1])) { $matches=array(); $matches[0]=$matches[1]=array('https://i3.ytimg.com/vi/'.$match[1].'/hqdefault.jpg'); } }
Not well tested but seems to work.
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘auto-post-thumbnail hack to use the youtube image when no other images’ is closed to new replies.