Support

Account

Home Forums ACF PRO YouTube Thumbnail Object with oEmbed field? Reply To: YouTube Thumbnail Object with oEmbed field?

  • Yes, it’s possible, but you’ll have to do a bit of string matching to find the id. For example:

    
    $video = get_field( 'oembed_video' );
    
    preg_match('/src="(.+?)"/', $video, $matches_url );
    $src = $matches_url[1];	
    
    preg_match('/embed(.*?)?feature/', $src, $matches_id );
    $id = $matches_id[1];
    $id = str_replace( str_split( '?/' ), '', $id );
    
    var_dump( $id );

    And then to grab the thumbnail:

    <img src="http://img.youtube.com/vi/<?php echo $id; ?>/mqdefault.jpg">

    More info on YouTube thumbnails:
    http://stackoverflow.com/questions/2068344/how-do-i-get-a-youtube-video-thumbnail-from-the-youtube-api