-
-
Save pavlo-bondarchuk/76a89d41a6b5b1321ae1683ffe169187 to your computer and use it in GitHub Desktop.
add_preload_featured_image
This file contains hidden or 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 add_preload_featured_image() { | |
if (is_single() || is_page()) { | |
if (has_post_thumbnail()) { | |
$post_thumbnail_id = get_post_thumbnail_id(); | |
$post_thumbnail_url = wp_get_attachment_image_url($post_thumbnail_id, 'full'); | |
if ($post_thumbnail_url) { | |
echo '<link rel="preload" href="' . esc_url($post_thumbnail_url) . '" as="image" type="image/webp">'; | |
} | |
} | |
} | |
} | |
add_action('wp_head', 'add_preload_featured_image'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment