• Resolved looot

    (@looot)


    <img src="http://localhost/wp-content/uploads/2022/02/long-sleeve-tee-2-300x300.jpg" class="attachment-woocommerce_thumbnail size-woocommerce_thumbnail" alt="" loading="lazy" srcset="http://localhost/wp-content/uploads/2022/02/long-sleeve-tee-2-300x300.jpg 300w, http://localhost/wp-content/uploads/2022/02/long-sleeve-tee-2-100x100.jpg 100w, http://localhost/wp-content/uploads/2022/02/long-sleeve-tee-2-500x500.jpg 500w, http://localhost/wp-content/uploads/2022/02/long-sleeve-tee-2-150x150.jpg 150w, http://localhost/wp-content/uploads/2022/02/long-sleeve-tee-2-768x768.jpg 768w, http://localhost/wp-content/uploads/2022/02/long-sleeve-tee-2.jpg 801w" sizes="(max-width: 300px) 100vw, 300px" width="300" height="300">

    I’ve searched everywhere I can think for class="attachment-woocommerce_thumbnail size-woocommerce_thumbnail" with no luck.

    I tried adding the classes with Jquery.

    `<script>
    ‘use strict’;
    ( function( $ ) {

    <?php if (is_shop()): ?>
    // Add classes to the img tag
    $(‘.attachment-woocommerce_thumbnail’).addClass(‘w-full md:h-96 sm:h-auto object-cover’);
    <?php else: ?>
    $(‘.attachment-woocommerce_thumbnail’).addClass(‘w-full object-cover 2md:h-96’);
    <?php endif ?>
    } )(jQuery);
    </script>`

    It works at first, but I use an infinite scroll plugin someone else wrote, and it does not add the classes to the new images.

    • This topic was modified 4 years ago by looot.
Viewing 7 replies - 1 through 7 (of 7 total)
Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘How to add classes to Woocommerce product img’ is closed to new replies.