Skip to content

Instantly share code, notes, and snippets.

@patrickposner
Last active February 19, 2020 20:18
Show Gist options
  • Select an option

  • Save patrickposner/ab4ca099b4021cca51f0c6dc9831a828 to your computer and use it in GitHub Desktop.

Select an option

Save patrickposner/ab4ca099b4021cca51f0c6dc9831a828 to your computer and use it in GitHub Desktop.
Visual Composer - YT Videos with auto loop
<?php
add_action('wp_footer', 'pp_convert_youtube' );
function pp_convert_youtube() {
?>
<script>
jQuery(document).ready(function( $ ) {
$(".wpb_video_wrapper iframe").each( function() {
var old_src = $(this).attr("src");
/* get the youtube id from the src attribute */
var yt_id = old_src.match("embed/(.*)?feature=oembed");
yt_id = yt_id[1].slice(0,-1);
/* now add the missing parameters and update src attribute */
var new_src = old_src + '&loop=1&playlist=' + yt_id;
$(this).attr("src", new_src);
});
});
</script>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment