Skip to content

Instantly share code, notes, and snippets.

@seoagentur-hamburg
Created April 26, 2016 13:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seoagentur-hamburg/b663074527f686c23037aca3f6431e3c to your computer and use it in GitHub Desktop.
Save seoagentur-hamburg/b663074527f686c23037aca3f6431e3c to your computer and use it in GitHub Desktop.
Teil 2 des Codes für Defer video Loading
<?php
function democratic_defer_video_load() {
if ( is_single() ) {
?>
<!-- Defer Videos for Performance -->
<script>function init(){var videoDefer=document.getElementsByTagName('iframe');for(var i=0;i<videoDefer.length;i++){if(videoDefer[i].getAttribute('data-src')){videoDefer[i].setAttribute('src',videoDefer[i].getAttribute('data-src'));}}}window.onload=init;</script>
<!-- END Defer Videos -->
<?php
}
}
add_action( 'wp_footer', 'democratic_defer_video_load');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment