-
-
Save koko-ng/c22889605e43f96adb7c957301e46bab to your computer and use it in GitHub Desktop.
ACF OEmbed with thumbnails
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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