Created
July 24, 2024 08:33
-
-
Save braddalton/6e841a15823893253a876520eb215c08 to your computer and use it in GitHub Desktop.
Pre Load Product Images WooCommerce
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action('wp_head', 'rl_add_preload', 1); | |
function rl_add_preload() { | |
global $product; | |
if (is_product() && isset($product)) { | |
$image = wp_get_attachment_image_src($product->get_image_id(), "edit"); | |
if ($image && is_array($image) && isset($image[0])) { | |
echo PHP_EOL . '<link rel="preload" as="image" href="' . esc_url($image[0]) . '">' . PHP_EOL; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment