Last active
February 19, 2020 20:18
-
-
Save patrickposner/ab4ca099b4021cca51f0c6dc9831a828 to your computer and use it in GitHub Desktop.
Visual Composer - YT Videos with auto loop
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 | |
| 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