Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
How to speed up you your Divi gallery if you are using only the first thumbnail. See the related post here:
// 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