RogerM Posted August 17, 2021 Share Posted August 17, 2021 Hi there guys! I am at the moment trying to learn PHP as I want to get better at WordPress development and speed/performance optimization. Right now I want to build a simple plugin (or just insert this code snippet directly into the function.php file) that allows me to preload all feature images from a blog and, at the same time, exclude these featured images from lazy loading. This is what I got thus far... // preloading feature images for blog posts function featureimagepreload(){ if( is_single() ){ $featured_img_url = get_the_post_thumbnail_url(get_the_ID(),'full'); echo '<link rel="preload" as="image" href="'.$featured_img_url.'"/>'; } } add_action( 'wp_head', 'featureimagepreload'); Thoughts? Quote Link to comment https://forums.phpfreaks.com/topic/313562-preloading-featured-images-in-wordpress/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.