Viewing 17 posts - 1 through 17 (of 17 total)
  • Author
    Posts
  • #1312045

    Despite being above the fold, the main woocommerce shop image is being lazy loaded. Tested on versions 4.8.2 & 4.8.4.

    <img width="705" height="470" src="...Hump-705x470.jpg" class="avia-img-lazy-loading-11192 attachment-shop_single size-shop_single" alt="" loading="lazy" srcset="...Hump-705x470.jpg 705w, ...Hump-300x200.jpg 300w, ...Hump-1030x686.jpg 1030w, ...Hump-768x512.jpg 768w, ...Hump.jpg 1280w" sizes="(max-width: 705px) 100vw, 705px">

    #1312954

    Hey Jason,

    Thank you for the inquiry.

    Where can we see the issue? Please post the site URL in the private field. The theme automatically adds the lazy loading attribute to all images regardless of their position in the document. If you want to disable lazy loading on product pages, you can add this code in the functions.php file.

    add_action("wp", function() {
    	if(is_singular("product")) {
    		add_filter( 'wp_lazy_loading_enabled', "__return_false", 999 );
    	}
    }, 999);
    

    Best regards,
    Ismael

    #1313049

    Hi Ismael,

    I do not want to disable lazy loading on product pages, they are the most important page on my site.

    What I would like is that lazy loading would be disabled on the main image on the product page because it is above the fold.

    Can this please be fixed in the plugin for all ecommerce stores running enfold?

    Thanks,
    Jason

    #1313773

    Hi,

    You can try this script in the functions.php file to remove the loading attribute from the product image.

    
    function ava_custom_script_remove_lazy(){
      ?>
      <script>
            (function($) {
                $(document).ready(function($) {
      		$('.size-shop_single').removeAttr('loading');
      	    });
            })(jQuery);
      </script>
      <?php
    }
    add_action('wp_footer', 'ava_custom_script_remove_lazy');
    

    Best regards,
    Ismael

    #1315178

    Hi Ismael,

    The fix will need to be in PHP to have any affect on the browser. jQuery would be executed after the html was parsed and therefore have no effect on lazyloading / preloading.

    Can you fix this in the theme for your ecommerce customers?

    Thanks,
    Jason

    #1315197

    Hi,

    The lazy loading is actually a native browser feature, it is not from jQuery and it is triggered once the document is ready or when an image is visible in the view port. Removing the loading attribute immediately once the document is ready should prevent the image from being lazy loaded.

    You can see the current browser support in the following link.

    // https://caniuse.com/loading-lazy-attr

    Did you test the script?

    Best regards,
    Ismael

    #1315852

    I am aware of how lazy loading works.

    You provided a fix to remove the ‘loading’ attribute as a jQuery script… this is not going to have any affect, as jQuery runs after the page load!

    • This reply was modified 3 years, 4 months ago by Jason.
    #1316178

    Hi!

    I see. Sorry for the confusion. Yes, you might be right. Unfortunately, I am not sure if it is possible to detect above the fold content using PHP. You might be able to unset the loading attribute using the following filter.

    add_filter( 'wp_get_attachment_image_attributes', function( $attr, $attachment, $size ) {
        if ( $size === 'shop_single' ) {
            unset( $attr['loading'] );
        }
        return $attr;
    } );
    

    // https://developer.wordpress.org/reference/hooks/wp_get_attachment_image_attributes/

    You can create the logic based on the $attachment info, or check if the $size is equal to “shop_single”.

    Regards,
    Ismael

    #1316277

    Ismael,

    As this issue would be affecting every Enfold store owner, and Enfold is marketed as Woocommerce compatible, can we get a fix like the above included in the plugin?

    It should be noted that Woocommerce is not adding the attribute, enfold is.

    Thanks,
    Jason

    #1316593

    Hey!

    We have forwarded the issue to our channel for further consideration. For the meantime, please provide a link to any of your product page so that we can check it. You might have to keep the above filter temporarily.

    Thank you for your patience.

    Best regards,
    Ismael

    #1317147

    I have a workaround in place so checking my site is not going to help you. Any test on a default install of Enfold/Woo should show this.

    Looking forward to a fix.

    #1317288

    Hi Jason,

    Thank you for following up.

    The filter above actually removes the loading attribute of the product’s main image (shop_single), so it should be a viable solution, temporarily. Did you try it?

    Best regards,
    Ismael

    #1317297

    As written, the code causes a 500 error on page load. I have a workaround but am looking for a permanent solution in the theme.

    Thanks,
    Jason

    #1317418

    Hi,

    The same code works fine on our end. It removes the loading attribute of the single product featured or main image. Did you copy it directly from the forum, and not from your email?

    What is your workaround? Mind it sharing it here so that we could implement it to the theme.

    Best regards,
    Ismael

    #1317419

    Hi,

    You could also try this modified enfold/config-woocommerce/config.php file.

    // https://pastebin.com/i2ereGyM

    We added the avia_woocommerce_lazy_load function, which is almost the same as the filter above.

    Best regards,
    Ismael

    #1317460

    The code as written in #1316178 gives

    [Thu Aug 19 18:26:34.245543 2021] [proxy_fcgi:error] [pid 21132:tid 140628638934784] [client x:59856] AH01071: Got error 'PHP message: PHP Fatal error: Uncaught ArgumentCountError: Too few arguments to function {closure}(), 1 passed in /wp-includes/class-wp-hook.php on line 305 and exactly 3 expected

    Wordpress 5.8 / WooCommerce 5.5.1.

    If you can commit that pastebin version to the next plugin release that would be perfect :)

    Thanks,
    Jason

    #1317468

    Hi,

    Thank you for the feedback.

    The pastebin version is already merged for the next update.

    The code as written in #1316178 is missing the priority and number of parameters – should be:

    
    add_filter( 'wp_get_attachment_image_attributes', function( $attr, $attachment, $size ) {
        if ( $size === 'shop_single' ) {
            unset( $attr['loading'] );
        }
        return $attr;
    }, 10, 3 );
    

    Glad that this fixes the problem.

    Best regards,
    Günter

Viewing 17 posts - 1 through 17 (of 17 total)
  • You must be logged in to reply to this topic.