Skip to content

Instantly share code, notes, and snippets.

@KevinBatdorf
Last active February 2, 2021 02:50
Show Gist options
  • Save KevinBatdorf/cefa48ea431fa9a9001f6aae22d9f08d to your computer and use it in GitHub Desktop.
Save KevinBatdorf/cefa48ea431fa9a9001f6aae22d9f08d to your computer and use it in GitHub Desktop.
Add YouTube support to MetaSlider with Easy Fancybox
<?php
// Requires MS Lightbox
add_filter('metaslider_lightbox_supported_plugins', function ($attributes) {
return [
'Easy FancyBox' => [
'location' => 'easy-fancybox/easy-fancybox.php',
'settings_url' => 'options-media.php',
'rel' => 'lightbox',
]
];
});
// Make sure the YouTube option is set from the Easy Fancybox settings page
// requires MS pro
add_filter('easy_fancybox_inline_script', function ($js) {
return "
window.jQuery('.ms-youtube').each(function(i, video) {
var msytid = window.jQuery(video).find('.youtube').attr('data-id');
if (msytid) {
var galleryId = window.jQuery(video).closest('.metaslider').find('a[rel]').attr('rel');
window.jQuery(video).wrapInner('<a rel=\''+galleryId+'\' href=\'https://youtu.be/'+msytid+'?hd=1&fs=1&autoplay=1\'>');
}
});
$js";
}, 10, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment