Tell WordPress how many images at the top of each page to load straight away instead of lazily, to speed up your hero image.
add_filter( 'wp_omit_loading_attr_threshold', function (): int {
return 2; // The first 2 content images load eagerly.
} );
Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.
Lazy loading delays images until they scroll into view. That’s great for images further down, but it slows down images visible straight away, like a hero image, and hurts Largest Contentful Paint. WordPress already skips lazy loading for the first content image. This snippet lets you change how many.
WordPress counts the images it outputs in the main content. For the first N, set by wp_omit_loading_attr_threshold, it leaves out loading="lazy", and gives the first large one fetchpriority="high". Every image after that is lazy-loaded as usual.
View the source of a post with several images. The first two <img> tags should have no loading="lazy" attribute; later ones should.