• jimon07

    (@jimon07)


    Is there any snippet you can provide in order to remove the lazy loading of the first X images of a product category page? This would help a lot with website speed.

    I tried some snippets but i cannot make it work it does nothing.

    function add_skip_lazy_class_to_first_six_product_images($html, $attachment_id, $post_id, $image_size, $icon) {
    // Only apply this on product category pages
    if (!is_product_category()) {
    return $html;
    }

    static $image_count = 0; // Keep track of how many images have been processed

    // Check if the image is part of the main product image (if it's an actual product image)
    if (strpos($html, 'class="wp-post-image"') !== false) {
    $image_count++;

    // Add the 'skip-lazy' class to the first six images
    if ($image_count <= 6) {
    $html = str_replace('<img', '<img class="skip-lazy"', $html);
    }
    }

    return $html; // Return the modified HTML
    }

    add_filter('wp_get_attachment_image', 'add_skip_lazy_class_to_first_six_product_images', 10, 5);
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.