WordPress Image Optimization – AVIF, WebP, Lazy Loading, and Core Web Vitals
Published: May 20, 2026 · Author: Marcin Szewczyk-Wilgan
Images account for 40–60% of a typical web page's total byte weight. On WordPress sites, unoptimized images are the single most common cause of poor Core Web Vitals scores – particularly Largest Contentful Paint. The good news is that image optimization is one of the highest-ROI performance improvements you can make: the techniques are well established, the tooling in 2026 is excellent, and the impact on LCP is immediate and measurable.
Modern Image Formats – AVIF and WebP
Serving images in the right format is the first and most impactful optimization step. The era of JPEG and PNG as defaults is over for web use.
<picture> elements with AVIF as the first source and WebP as a fallback when both formats are enabled. Browsers pick the first format they support. You do not need to manage this manually – it works transparently through wp_get_attachment_image() and the_post_thumbnail().srcset and sizes – Serving the Right Dimensions
Format optimization reduces bytes per pixel. The srcset and sizes attributes ensure you are not sending a 1920px image to a mobile device displaying it at 390px.
Multiple resolution variants
WordPress automatically generates a srcset attribute listing all available size variants of an image, with their widths in pixels. The browser then picks the most appropriate size based on the display width and device pixel ratio. This works correctly for all images inserted via the block editor or theme functions.
Telling the browser the display width
The sizes attribute tells the browser how wide the image will be rendered before it downloads it. WordPress generates a reasonable default, but for images in complex layouts (CSS Grid, multi-column) the default may be inaccurate. Incorrect sizes causes browsers to download larger images than needed.
Controlling what WordPress generates
WordPress core registers four default sizes. Themes and plugins add more. You can register custom sizes with add_image_size() and remove unused ones with the intermediate_image_sizes_advanced filter. Each registered size generates a file on disk for every uploaded image, so fewer active sizes means less storage and faster uploads.
Rebuilding thumbnails after changes
Changing registered image sizes does not automatically resize existing images. Use WP-CLI (wp media regenerate) or the Regenerate Thumbnails plugin to rebuild all thumbnails. On large media libraries, run this from the command line to avoid browser timeouts.
Lazy Loading and fetchpriority
WordPress 5.5 (August 2020) added loading="lazy" to images automatically. WordPress 6.3 (August 2023) added fetchpriority="high" to the first in-content image. These two attributes work together to prioritize what matters and defer what does not.
the_content() and to the_post_thumbnail() when it is the first image on the page. For pages where the LCP element is a hero image outside the content area (e.g., in the theme header), you may need to add this attribute manually or via a plugin.<link rel="preload"> tag in the <head> alongside fetchpriority="high" provides the most reliable early fetch. This is particularly effective for hero images defined in CSS (background-image) rather than HTML, which the browser's preload scanner cannot otherwise discover early.decoding="async" attribute allows the browser to decode image data off the main thread, reducing the risk of layout jank during image rendering. WordPress adds this automatically. It is most beneficial for large images on content-heavy pages.Compression and Quality Settings
Format and dimensions determine the theoretical size floor; compression settings determine how close to that floor you actually get.
jpeg_quality filter. Values between 75 and 85 are generally the sweet spot for web images – below 70 introduces visible artifacts, above 85 adds size without noticeable quality gain.WooCommerce Image Optimization
WooCommerce sites face an amplified version of the image optimization problem. Product catalogs often contain hundreds of images, each processed into multiple sizes. Getting this right matters for both performance and storage.
Default product image dimensions
WooCommerce registers three image sizes by default: woocommerce_thumbnail (the catalog grid image), woocommerce_single (the product page main image), and woocommerce_gallery_thumbnail (the small thumbnail strip). Dimensions are configurable in WooCommerce → Settings → Products → Images. Set these based on your theme's actual display dimensions to avoid serving oversized images.
Lazy loading gallery images
Product gallery images (all images beyond the first) are excellent candidates for lazy loading. The visitor sees the main product image immediately; additional gallery shots load only when they scroll to or click them. Ensure your theme or WooCommerce gallery JavaScript handles lazy-loaded images correctly after a swap.
Category pages with many products
Category pages displaying 24, 48, or more products can have enormous total image weight. Combine srcset for responsive sizing with lazy loading for below-the-fold products. The first row of products (visible on initial load) should not be lazy loaded – they contribute directly to LCP measurement.
Offloading media delivery
For WooCommerce stores with large product catalogs, serving images via a CDN (Cloudflare, BunnyCDN, or Amazon CloudFront) dramatically reduces server load and improves delivery speed for geographically distributed customers. Combine CDN delivery with Cloudflare Polish (automatic WebP/AVIF conversion at the edge) for maximum effect.
Practical Checklist
Work through this checklist to assess and improve image performance on any WordPress site:
<picture> elements with AVIF/WebP sources.fetchpriority="high" and does NOT have loading="lazy". Add a <link rel="preload"> in the head if it is a CSS background image.wp media image-size --fields=name,width,height --format=table via WP-CLI. Remove unused sizes to reduce upload processing time and storage.nohup or as a background process to avoid timeouts.Summary
Image optimization in WordPress is a solved problem in 2026 – the format support, tooling, and WordPress core integrations are all mature. AVIF with WebP fallback, properly configured srcset/sizes, lazy loading for below-the-fold images, and fetchpriority for the LCP element will reliably move you from a failing Core Web Vitals score to a passing one in most cases. The key is applying these techniques systematically and verifying results in PageSpeed Insights field data, not just lab scores.


