Skip to content

Instantly share code, notes, and snippets.

@erezLieberman
Last active August 21, 2017 15:09
Show Gist options
  • Save erezLieberman/f2ac621fefbac7219abd to your computer and use it in GitHub Desktop.
Save erezLieberman/f2ac621fefbac7219abd to your computer and use it in GitHub Desktop.
embed video to wp acf
<div class="videoWrapper">
<!-- from here: http://css-tricks.com/NetMag/FluidWidthVideo/Article-FluidWidthVideo.php -->
<?php if( get_field('youtube_url') ){
$embed_code = wp_oembed_get( get_field('youtube_url') );
echo $embed_code;
} ?>
</div>
@erezLieberman
Copy link
Author

if you want auto play use this in functions.php:
function modify_youtube_embed_url($html) {
return str_replace("?feature=oembed", "?feature=oembed&autoplay=1", $html);
}
add_filter('oembed_result', 'modify_youtube_embed_url');

if its inside modal use this in jquery:
//play and stop the youtube video inside the bootstrap modal
youtube_url = $('.backstrach_img .embed-container iframe').attr('src');
youtube_url = youtube_url.replace("?feature=oembed", "?feature=oembed&autoplay=1");
$('.play_btn').on('click',function(){
$('.backstrach_img .embed-container iframe').attr('src',youtube_url);
})

$('.backstrach_img .modal').on('hidden.bs.modal', function () {
 $('.backstrach_img .embed-container iframe').attr('src','');  
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment