Home › Forums › Support › Preload Blog Post Attachment Image on Every Post/Page This topic has 3 replies, 2 voices, and was last updated 3 years, 8 months ago by David. Viewing 4 posts - 1 through 4 (of 4 total) Author Posts August 20, 2020 at 5:26 pm #1411944 David This works, apart from minor console error. <?php $attachment_image = wp_get_attachment_url( get_post_thumbnail_id() ); ?> <link rel=”preload” as=”image” href=”<?php echo esc_url( $attachment_image ); ?>”> Place the code in header.php in the head section. ** If the attachment image is empty, it will show a warning in the console for incorrect preload value. August 20, 2020 at 7:17 pm #1411984 David Answer: this now only runs if there is an active thumbnail. No more errors! <?php if (has_post_thumbnail()) { $attachment_image = wp_get_attachment_url( get_post_thumbnail_id() ); echo ‘<link rel=”preload” as=”image” href=”‘.$attachment_image.'”>’; } ?> August 21, 2020 at 4:24 am #1412395 DavidStaff Customer Support Looks good 🙂 Glad to hear you found a solution. August 21, 2020 at 9:32 am #1412951 David Hi David, Yes, I’m over the moon with my first ever snippet. All 3 x lines of it. 🙂 Should be useful to anyone wishing to improve upon their LCP times in PageSpeed Insights. Thanks, D Author Posts Viewing 4 posts - 1 through 4 (of 4 total) You must be logged in to reply to this topic. Log In Username: Password: Keep me signed in Log In