Skip to content

Instantly share code, notes, and snippets.

@KevinBatdorf
Created May 28, 2019 17:27
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 KevinBatdorf/e6c6ab1dc57bff5ec411f8297fe92aa9 to your computer and use it in GitHub Desktop.
Save KevinBatdorf/e6c6ab1dc57bff5ec411f8297fe92aa9 to your computer and use it in GitHub Desktop.
Jetpack breaks images on MetaSlider, and this disabled JetPack from doing so.
<?php
add_filter('jetpack_photon_skip_image', 'metaslider_remove_jetpack', 10, 2);
add_filter('jetpack_lazy_images_skip_image_with_attributes', 'metaslider_remove_jetpack', 10, 2);
function metaslider_remove_jetpack($val, $src) {
// The lazy load filter send the src as a param
$src = isset($src['src']) ? $src['src'] : $src;
// Get an array of slideshow images
$slide_image_names = array_map(function ($post) {
$image = wp_get_attachment_url(get_post_thumbnail_id($post->ID));
// Extract the filename only from the slide image as WP will add sizes
return pathinfo(end(explode('/', $image)))['filename'];
}, get_posts(['post_type' => 'ml-slide', 'posts_per_page' => -1]));
// Filter through every slide image and see if Jetpack is trying to serve it
$skip = array_filter($slide_image_names, function ($slide_src) use ($src) {
return strpos($src, $slide_src) !== false;
});
return count($skip) ? true : $val;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment