Forums

Auto Post Thumbnail
auto-post-thumbnail hack to use the youtube image when no other images (2 posts)

  1. _ck_
    Member
    Posted 9 months ago #

    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('http://i3.ytimg.com/vi/'.$match[1].'/hqdefault.jpg');
    		}
    	}

    Not well tested but seems to work.

  2. skittles
    Member
    Posted 2 months ago #

    Cant believe this isnt in by default already!

Reply

You must log in to post.

About this Plugin

About this Topic