Created
July 2, 2015 13:50
-
-
Save louisnovick/27f99334cf2f71278b84 to your computer and use it in GitHub Desktop.
Create a Wordpress shortcode for lazy loading videos
This file contains 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
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