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
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.