Skip to content

Instantly share code, notes, and snippets.

@koko-ng
Forked from yratof/functions.php
Last active October 17, 2017 16:47
Show Gist options
  • Save koko-ng/c22889605e43f96adb7c957301e46bab to your computer and use it in GitHub Desktop.
Save koko-ng/c22889605e43f96adb7c957301e46bab to your computer and use it in GitHub Desktop.
ACF OEmbed with thumbnails
<?php
/* Pull apart OEmbed video link to get thumbnails out*/
function get_video_oembed_data( $video_uri ) {
//second false skip ACF pre-processcing
$url = get_field('videos', false, false);
//get wp_oEmed object, not a public method. new WP_oEmbed() would also be possible
$oembed = _wp_oembed_get_object();
//get provider
$provider = $oembed->get_provider($url);
//fetch oembed data as an object
$oembed_data = $oembed->fetch( $provider, $url );
return $oembed_data->thumbnail_url;
}
<?php
//For use with a single field.
$video_url = get_field('video', FALSE, FALSE); //URL
$video_data = get_video_oembed_data($video_url);
<?php //Lightbox Link via Thumbnail ?>
<a href="#lightbox"><img src="<?php echo $video_data->thumbnail_url; ?>"/></a>
<?php //Lightbox Element with Video Embed Code ?>
<div id="lightbox" class="embed-container">
<?php echo $video_data->html; ?>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment