Skip to content

Instantly share code, notes, and snippets.

@louisnovick
Created July 2, 2015 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save louisnovick/27f99334cf2f71278b84 to your computer and use it in GitHub Desktop.
Save louisnovick/27f99334cf2f71278b84 to your computer and use it in GitHub Desktop.
Create a Wordpress shortcode for lazy loading videos
function lazy_load_videos($atts) {
$a = shortcode_atts( array(
'id' => 'something else',
'width' => '',
'height' => ''
), $atts );
$stringbean = '<div class="js-lazyYT ';
if( !empty($a['height']) ){
$stringbean .= '" data-height="'.$a['height'].'" style="height:'.$a['height'].'; width:'.$a['width'].';" data-width="'.$a['width'].'"';
}else{
$stringbean .= 'jz-lazyYT-padd " data-ratio="16:9" data-width="1280" data-height="720"';
}
$stringbean .= 'data-youtube-id="'.$a['id'].'" data-parameters="rel=0&showinfo=0&modestbranding=1&vq=large&wmode=transparent"></div>';
return $stringbean;
}
add_filter('widget_text', 'do_shortcode');
add_shortcode('lazyload', 'lazy_load_videos');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment