Preload First Image on Front Page

This snippet preloads the first image on your WordPress homepage content to improve Largest Contentful Paint. It scans for the first <img>, retrieves its URL (and srcset/sizes if available), and injects a <link rel="preload" as="image"> tag into the page head. This ensures the hero image loads earlier, boosting Core Web Vitals performance.

If this code helped you, or you have any questions on implementation, don’t hesitate to reach out.