Skip to content

Instantly share code, notes, and snippets.

@braddalton
Created July 24, 2024 08:33
Show Gist options
  • Save braddalton/6e841a15823893253a876520eb215c08 to your computer and use it in GitHub Desktop.
Save braddalton/6e841a15823893253a876520eb215c08 to your computer and use it in GitHub Desktop.
Pre Load Product Images WooCommerce
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