Last active
August 1, 2024 17:12
-
-
Save jinsley8/70c16cae258fdcf8b7be84d6ee08ba45 to your computer and use it in GitHub Desktop.
Preload featured image in WordPress
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
function preload_featured_image() { | |
if (has_post_thumbnail()) { | |
$attachment_image = wp_get_attachment_url(get_post_thumbnail_id()); | |
if ($attachment_image) { | |
echo '<link rel="preload" fetchpriority="high" as="image" href="' . esc_url($attachment_image) . '">'; | |
} | |
} | |
} | |
add_action('wp_head', 'preload_featured_image'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment