// 1. Single product page: preload LCP main image in
add_action( 'wp_head', function() { if ( function_exists( 'is_product' ) && is_product() ) { $thumb_id = get_post_thumbnail_id( get_queried_object_id() ); if ( $thumb_id ) { $img_url = wp_get_attachment_image_url( $thumb_id, 'woocommerce_single' ); if ( $img_url ) { echo '' . "\n"; } } } }, 1 );// 2. Single product main image + Shop first product thumbnail: fetchpriority="high" & no lazy-load add_filter( 'wp_get_attachment_image_attributes', function( $attr ) { static $product_main_done = false; static $shop_first_done = false; $class = isset( $attr['class'] ) ? $attr['class'] : '';if ( ! $product_main_done && function_exists( 'is_product' ) && is_product() && strpos( $class, 'wp-post-image' ) !== false ) { $product_main_done = true; $attr['fetchpriority'] = 'high'; $attr['loading'] = 'eager'; $attr['data-no-lazy'] = '1'; }if ( ! $shop_first_done && function_exists( 'is_shop' ) && ( is_shop() || is_product_category() ) && strpos( $class, 'attachment-woocommerce_thumbnail' ) !== false ) { $shop_first_done = true; $attr['fetchpriority'] = 'high'; $attr['loading'] = 'eager'; $attr['data-no-lazy'] = '1'; }return $attr; }, 20 ); Skip to main content