function preload_product_page_featured_page_automatic() { if ( is_product() ){ $attachment_ids[0] = get_post_thumbnail_id( $product->id ); $attachment_full = wp_get_attachment_image_src($attachment_ids[0], 'full' ); $attachment = wp_get_attachment_image_src($attachment_ids[0], 'woocommerce_single' ); $attachment_mobile = wp_get_attachment_image_src($attachment_ids[0], 'woo-product-single-image-size-hook' ); echo ''. PHP_EOL .'<!-- Preload Product Page First Featured Image -->'. PHP_EOL .'<link rel="preload" href="' .$attachment[0]. '" as="image">'. PHP_EOL .'<!-- End Preload Product Page First Featured Image -->'; } } add_action( 'wp_head', 'preload_product_page_featured_page_automatic');
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter