WordPress
WordPress Image Optimization Without the Plugin Guesswork
WordPress image optimization is the practice of serving the right image format, resolution and loading priority for each viewport so pages reach Largest Contentful Paint faster. In my builds it means AVIF or WebP with a JPEG fallback, responsive srcset, explicit width and height, meaningful alt text, and fetchpriority on the hero image.
What WordPress image optimization actually fixes
Most WordPress sites do not have an image problem because of file size alone. They have a delivery problem: a 4000-pixel upload is rendered into a 300-pixel card, the browser downloads every variant, the hero image loads late, and the layout jumps while dimensions are resolved. WordPress image optimization addresses each of those failures separately. WordPress already generates intermediate sizes on upload, but it emits them without a sizes attribute unless the theme supplies one, so the browser cannot choose intelligently. I start by identifying the single largest contentful element on the page, then work backwards from the rendered size to the source file. That ordering matters more than any plugin setting: compressing an image nobody sees does nothing for Largest Contentful Paint.
- Serve resized variants instead of one oversized original
- Match the delivered resolution to the largest rendered slot
- Remove layout shift before tuning compression
- Prioritise the LCP element over decorative images
AVIF and WebP: which format to serve and when
AVIF and WebP both beat JPEG at comparable perceptual quality, but they solve slightly different problems. WebP is supported everywhere that matters today and is a safe default for theme-generated thumbnails. AVIF usually compresses better for photographic material and gradients, but encoding is slower and very large batches can strain shared hosting. In my WordPress builds I generate both at upload time, let the browser negotiate through a picture element or a content-negotiation layer, and keep the original JPEG as the fallback inside source. What I avoid is converting everything blindly: line art, screenshots with sharp text and already-compressed PNGs sometimes come out larger in AVIF. Test a representative sample from the media library before enabling a global rewrite rule.
- WebP as the default for thumbnails and in-content images
- AVIF for photographic heroes where encoding cost is acceptable
- JPEG or PNG fallback in the final source element
- Skip re-encoding screenshots and diagrams that grow in size
- Regenerate existing media after changing image sizes
Responsive srcset and sizes that browsers can use
srcset gives the browser a list of candidate files; sizes tells it how wide the image will be displayed. WordPress writes srcset automatically but does not write sizes, which means browsers often assume 100vw and download a much larger file than the layout needs. I set sizes from the actual CSS grid: a fixed-width sidebar thumbnail gets a pixel value, a full-width hero gets vw units with a max-width cap. The descriptors must match the generated sizes, because using w descriptors with files that are not scaled to those widths produces wrong calculations. On custom themes I emit the attribute from the same PHP function that renders the markup, so a layout change cannot silently invalidate the image configuration.
- Add sizes manually when building custom theme image markup
- Use w descriptors with genuinely resized generated files
- Cap full-width images at their real max-width in CSS
- Check the chosen candidate in DevTools Network panel
Explicit dimensions and why they stop layout shift
A browser needs intrinsic dimensions before it can reserve space. When width and height are missing, the element collapses to zero until the file arrives, then pushes content down. That is Cumulative Layout Shift, a measurable Core Web Vitals failure rather than a cosmetic detail. WordPress core adds width and height to images inserted through the editor, but page builders, lazy-loaded background images and hand-written theme templates frequently drop them. The fix is to emit the attributes from attachment metadata instead of hard-coding values, then use aspect-ratio or height:auto in CSS so the reserved box scales with the container. I check this on a throttled connection because fast local broadband hides the jump.
- Read dimensions from wp_get_attachment_image_src or metadata
- Never omit width and height on above-the-fold images
- Use CSS aspect-ratio for responsive containers
- Treat background-image elements separately with a spacer
Alt text that describes intent, not filename
Alt text is an accessibility requirement first and an SEO signal second. It should describe the purpose of the image in the surrounding context, not its filename or a keyword list. A product photo in a WooCommerce store might read "Rear view of the oak desk showing the cable port"; a decorative divider should have alt="" so screen readers skip it. In my WordPress work I put the alt value into the media library field and render it through wp_get_attachment_image, which keeps the text identical everywhere the image appears. I also reject empty alt on informative images and keyword-stuffed alt on decorative ones, both of which are common page-builder defaults that survive theme changes unnoticed.
- Describe the image function, not the file name
- Use empty alt for purely decorative graphics
- Keep alt consistent across the media library and templates
- Never repeat the target keyword mechanically
LCP image priority: loading, fetchpriority and above-the-fold rules
The LCP image is the single element that dominates the Largest Contentful Paint metric, and it should be treated differently from everything below the fold. It must not be lazy-loaded: adding loading="lazy" to the hero is the most common self-inflicted LCP regression I see in WordPress builds. I mark it for eager loading, set fetchpriority="high" on the img tag, preload it only when the URL is stable and not theme-swapped, and keep it out of a slider that mounts after JavaScript runs. Then I verify on a mid-range Android device over a throttled 4G profile, because desktop lab scores rarely reflect the users who actually wait.
- Never lazy-load the hero or any candidate LCP image
- Apply fetchpriority="high" to one image only
- Avoid client-side sliders for the first visible image
- Preload the hero only if the source URL is deterministic
- Measure LCP on throttled mobile, not desktop
How I verify image performance in a WordPress build
Verification happens in the browser, not in a plugin dashboard. I open the rendered page with an empty cache, inspect the Network panel for the exact file selected by srcset, confirm that the hero is not deferred by a lazy-load script, and check the Performance panel for LCP timing and any layout-shift entries. For the WordPress side I audit the media library for oversized originals and confirm that regenerated sizes exist after any theme change. Everything described here is part of the WordPress and technical SEO work I do at webdev-saif.com. I am Saif Al Jahan, a WordPress and PHP developer based in Mymensingh, Bangladesh, and I keep these checks in a repeatable checklist rather than relying on a one-off audit.
Frequently asked questions
Does WordPress convert images to WebP automatically?
WordPress core can generate WebP versions of uploaded JPEGs when the site supports it, but it does not always replace the rendered src with WebP in every theme context. You need picture markup or an output-rewrite layer. I generate WebP and AVIF at upload and declare the fallback explicitly.
Should I lazy-load every image on the page?
No. Lazy loading is for images below the fold. Applying it to the hero delays Largest Contentful Paint because the browser waits for layout before requesting the file. Keep the LCP image eager with fetchpriority set to high, and lazy-load galleries, thumbnails and footer graphics instead.
What is the difference between srcset and sizes?
srcset lists the candidate files with their pixel widths; sizes declares how wide the image renders at each breakpoint. Browsers need both to choose correctly. WordPress emits srcset but leaves sizes out of custom theme markup, so the browser often assumes the full viewport and pulls a larger file than necessary.
Do images affect Core Web Vitals?
Yes, mainly LCP and CLS. A large or late-loading hero pushes LCP past the 2.5 second threshold; missing width and height cause layout shift. INP is affected indirectly when heavy image processing blocks the main thread. I treat the hero image and its dimensions as part of the performance budget.
Do I need a plugin for WordPress image optimization?
Not necessarily. WordPress core handles resizing, srcset and WebP generation, and a theme can add sizes, dimensions, alt text and fetchpriority with a small function. I use a plugin only when a site needs bulk conversion of a large existing library, then remove it if theme code can handle the markup.
Why is my LCP image still slow after compression?
Compression addresses bytes, not scheduling. Common causes are lazy-loading the hero, a slider that injects the image after JavaScript, a render-blocking stylesheet ahead of the image request, or a preload pointing at a different URL than the final srcset choice. Check the request waterfall before compressing further.