Last active
May 10, 2016 15:06
-
-
Save kareemkibue/97d65680eb7a0b4239e72fabda0f5a2e to your computer and use it in GitHub Desktop.
WordPress YT Shortcode Embed (Page Load Considered)
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
<?php | |
echo do_shortcode('[youtube id="yXEfNoIZIP4"]'); | |
?> |
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
$(window).load(function(){ | |
$('iframe[data-src]').each(function(){ | |
$(this).attr('src', function(){ | |
return $(this).attr('data-src'); | |
}); | |
}); | |
}); |
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
<?php | |
/**************************************** YOUTUBE ****************************************/ | |
add_shortcode('youtube', 'embed_youtube_videos'); | |
function embed_youtube_videos($atts){ | |
ob_start(); | |
?> | |
<iframe src="" data-src="https://www.youtube.com/embed/<?php echo $atts['id']; ?>" frameborder="0" allowfullscreen width="<?php echo $atts['width']; ?>" height="<?php echo $atts['height']; ?>"></iframe> | |
<?php | |
return ob_get_clean(); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment