Skip to content

Instantly share code, notes, and snippets.

@StefanoCappellini
Last active November 18, 2021 01:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save StefanoCappellini/af4a09bfbab83cda69a2756aaa35b5e5 to your computer and use it in GitHub Desktop.
Save StefanoCappellini/af4a09bfbab83cda69a2756aaa35b5e5 to your computer and use it in GitHub Desktop.
How to speed up you your Divi gallery if you are using only the first thumbnail. See the related post here: https://www.stefanocappellini.it/posts/posts/make_divi_galleries_run_faster_without_thumbnails/
<?php
// Add this to your Divi child theme' functions.php file
// Remember to add the my_divi_fast_gallery class to all the galleries you want to optimize
add_filter('do_shortcode_tag', 'fast_gallery_tip', 105, 2);
function fast_gallery_tip($output, $tag){
if('et_pb_gallery' === $tag && strpos($output, 'my_divi_fast_gallery') !== false){
$pattern = '/<img[^>]*>/';
$index = 0;
return preg_replace_callback($pattern, function($matches) use (&$index) {
return $index++ === 0 ? $matches[0] : sprintf('<img src="%s/square.jpg"/>', get_stylesheet_directory_uri());
}, $output);
}
return $output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment