/ โ† Image Optimisation Fixes / Images in WordPress
In this guide
  1. What WordPress already does with images
  2. Which WordPress cause sits behind each finding
  3. The fix, step by step
  4. Child theme snippets
  5. Choosing between optimisation plugins
  6. WooCommerce and page builders
  7. Edge cases
  8. Keeping a WordPress media library healthy
  9. Questions and answers

What WordPress already does with images

Knowing the built-in behaviour saves you from installing plugins to do things WordPress already does, and helps you spot where it has been switched off.

๐Ÿ’ก Go to Tools, then Site Health, then Info, and open the Media Handling section. It shows whether the server uses Imagick or GD, and which formats that library supports. If AVIF or WebP is missing there, no plugin setting in WordPress can create those files on the server; you need your host to update the library, or a plugin that converts in the cloud.

Which WordPress cause sits behind each finding

Audit findingCommon WordPress cause
Oversized dimensionsTheme outputs the full size or a hard-coded URL; no registered size close to the display width; sizes assumes a wider column than the theme uses.
Oversized fileOriginals uploaded straight from a camera or phone; no compression plugin; quality set too high.
Old formatNo WebP or AVIF generation, or a plugin that creates WebP but never serves it.
Main image lazy-loadedAn optimisation plugin's script-based lazy loading on top of core; a page builder hero not recognised by core.
Missing dimensionsImages inserted as raw HTML, from old posts, or by builders and sliders that skip core functions.
Slow deliveryNo CDN; images served from shared hosting far from visitors; cache headers not set for the uploads folder.

The fix, step by step

Step 1

Check what the audit and Site Health report

Run the Image Optimisation audit on the home page, a typical post, a category archive and, on WooCommerce sites, a product page. Note which findings repeat across templates, because those come from the theme or a plugin rather than individual uploads. Then open Site Health, Info, Media Handling to see which image library and formats the server supports. Take a full backup of the database and the uploads folder before changing anything that rewrites images.

Step 2

Match registered sizes to the theme

Measure the widths your theme actually displays images at: content column, featured image, archive card and sidebar. Set the medium and large sizes in Settings, Media to values near those widths, and register any missing ones in a child theme with add_image_size(). Remove sizes registered by plugins or old themes you no longer use, using the intermediate_image_sizes_advanced filter, because each extra size adds files to every upload without helping any page.

Step 3

Cap upload size and set compression quality

Keep the big image threshold on, and lower it with the big_image_size_threshold filter if your widest layout is well under 2560 pixels, for example to 2048. Ask editors to export photos at a sensible size before uploading, and consider a plugin option that resizes originals on upload. If you run a compression plugin, let it control quality rather than also changing wp_editor_set_quality, so images are not compressed twice with different settings.

Step 4

Choose one optimisation plugin and configure it

Plugins such as ShortPixel, EWWW Image Optimizer, Smush and Imagify compress uploads and can create modern formats, some on your server and some through a cloud service. Pick one, deactivate the others, and check whether it compresses all generated sizes, not just the original. Decide whether to keep a backup of originals, which uses storage but lets you undo. Switch off the plugin's own lazy loading unless you are sure core lazy loading is disabled.

Step 5

Serve WebP or AVIF

Creating modern files is only half the job; the page must request them. Plugins do this in one of three ways: rewriting image tags into picture elements, using server rewrite rules that swap files by the browser's Accept header, or pointing images at a CDN that converts on the fly. Rewrite rules need Apache or nginx configuration and a Vary: Accept header. The Modern Image Formats plugin from the WordPress performance team is another option, generating WebP or AVIF sub-sizes on upload.

Step 6

Regenerate sizes for existing uploads

New size settings and format options only apply to future uploads. To update the existing library, run wp media regenerate --only-missing with WP-CLI, which creates missing sizes without redoing ones that exist, or use a regeneration plugin in batches. On large libraries, run it at a quiet time and watch disk space. Afterwards, run the optimisation plugin's bulk tool so new sizes are compressed and converted, then spot-check a few old posts.

Step 7

Sort out lazy loading and the main image

View the source of a page and check the first large image: it should have no loading="lazy" and ideally fetchpriority="high". If a plugin adds script-based lazy loading, look for data-src attributes and turn that feature off, or add the hero's class to the plugin's exclusion list. For builder heroes core does not recognise, set the image to load eagerly in the widget settings, or filter wp_get_loading_optimization_attributes in a child theme.

Step 8

Fix templates and builders that bypass core

Search the theme files for wp_get_attachment_url or the_post_thumbnail_url inside hand-built img tags, and replace them with wp_get_attachment_image() or the_post_thumbnail() with a named size, so srcset, sizes and dimensions return. In page builders, choose a registered size in each image widget instead of Full. For old posts with raw HTML images, re-insert key images or use the editor's Convert to blocks option.

Child theme snippets

Add these to a child theme's functions.php or a small site-specific plugin, never to the parent theme, where updates would remove them. The example sizes suit a fictional theme for Harbourside Bakery with a 760 pixel content column and 400 pixel archive cards.

<?php
// Sizes the theme actually uses.
add_action( 'after_setup_theme', function () {
    add_image_size( 'card', 400, 300, true );      // archive cards, cropped
    add_image_size( 'card-2x', 800, 600, true );   // cards on high-density screens
} );

// Lower the big image cap from 2560 to 2048 pixels.
add_filter( 'big_image_size_threshold', function () {
    return 2048;
} );

// Stop generating sizes nothing on the site uses.
add_filter( 'intermediate_image_sizes_advanced', function ( $sizes ) {
    unset( $sizes['1536x1536'], $sizes['2048x2048'] );
    return $sizes;
} );

// Describe the real content column in sizes for post images.
add_filter( 'wp_calculate_image_sizes', function ( $sizes, $size ) {
    return '(min-width: 800px) 760px, calc(100vw - 2rem)';
}, 10, 2 );

Be careful with the last filter: it changes sizes for every image output through core. If your templates have images at several widths, check the $size argument or apply the rule only in content, and give cards and headers their own values when you output them.

Outputting a featured image correctly

<?php
// Before: hard-coded full-size URL, no srcset, no dimensions.
echo '<img src="' . esc_url( get_the_post_thumbnail_url( null, 'full' ) ) . '">';

// After: core builds srcset, sizes, width, height and loading.
the_post_thumbnail( 'large', array(
    'sizes' => '(min-width: 800px) 760px, calc(100vw - 2rem)',
) );

Regenerating with WP-CLI

# Create missing sizes for all images, skipping ones already present
wp media regenerate --only-missing --yes

# Or regenerate only images attached in the last batch of IDs
wp media regenerate 1201 1202 1203 --yes

Choosing between optimisation plugins

The popular plugins overlap heavily, and their feature lists and plans change, so compare the current versions rather than relying on old reviews. The questions that actually separate them for your site are these:

โš ๏ธ Running two image optimisation plugins together is a common cause of broken images, double compression and conflicting lazy loading. The same applies when a caching plugin such as a performance suite also has an image section. Choose one owner for each task and switch the feature off elsewhere.

Hosting matters too. Some managed WordPress hosts compress images or serve them through their own CDN, and some block certain plugins. Check your host's documentation before adding a plugin that duplicates a service you already have.

WooCommerce and page builders

WooCommerce

WooCommerce registers its own sizes for product thumbnails, the single product image and gallery thumbnails, set under Appearance, Customise, WooCommerce, Product Images on classic themes, or declared by block themes. After changing them, regenerate thumbnails. The single product image is usually the main image on product pages, so check it is not lazy-loaded and that gallery images after the first are. Zoom and lightbox features load the full-size file; keep those originals reasonably sized.

Elementor, Divi and other builders

Builders have their own image widgets and background settings. Choose a registered size in each image widget rather than Full, and check whether the builder adds its own lazy loading on top of core. Section backgrounds set in a builder are CSS backgrounds, so they get neither srcset nor native lazy loading; for a hero, an image widget is usually faster than a background.

Edge cases

Keeping a WordPress media library healthy

Questions and answers

1. Which image optimisation plugin is best for WordPress?

There is no single best choice, because the right plugin depends on your hosting and how you want modern formats delivered. ShortPixel, EWWW Image Optimizer, Smush and Imagify all compress images and can create WebP, and several can create AVIF. Compare where compression happens, how formats are served, whether all sizes are processed and whether originals are kept. Whatever you choose, run only one and switch off features that overlap with other plugins.

2. Does WordPress convert images to WebP automatically?

Not by default in every setup. WordPress accepts WebP uploads from version 5.8 and AVIF from 6.5 if the server supports them, and developers can use the image_editor_output_format filter to save generated sizes in another format. The Modern Image Formats plugin from the WordPress performance team, or an optimisation plugin, is the usual way to convert JPEG and PNG uploads. Check Site Health to confirm your server's image library supports the format.

3. Why does WordPress create so many copies of each image?

Each copy is a different width, so browsers can download the one closest to the space the image fills. WordPress creates its default sizes, the extra large sizes added in version 5.3, and every size registered by your theme and plugins. Most sites carry sizes they never use, left over from old themes or plugins. Remove those with a filter, keep the ones your layout needs and regenerate thumbnails so the library matches.

4. How do I regenerate thumbnails without breaking my site?

Take a full backup first. Then use WP-CLI with wp media regenerate and the only-missing option, which adds missing sizes without recreating existing files, or a regeneration plugin that works in batches. Run it at a quiet time, because it is heavy on the server, and watch disk space. Pages that reference the old files keep working, since existing file names do not change unless you remove sizes entirely. Spot-check a few old posts afterwards.

5. Why is my WordPress hero image still lazy-loaded?

Core WordPress tries to leave the first images eager, but its guess depends on the theme outputting images through core functions in the expected order. An optimisation plugin with its own script-based lazy loading, a page builder hero or a slider can bypass that logic. Look at the page source for loading lazy or data-src on the hero, then exclude it in the plugin, change the widget setting or filter the loading attributes in a child theme.

6. Should I reduce the JPEG quality WordPress uses?

WordPress re-encodes generated sizes at a default JPEG quality of 82, which is a reasonable balance for most photos. If you use a compression plugin, let the plugin set quality instead, so images are not compressed twice with different settings. If you do not, lowering the value slightly with the wp_editor_set_quality filter can save bytes, but check photos with fine detail or gradients for visible banding before applying it across the site.

7. Do I need a CDN for WordPress images?

Not always, but it often helps when visitors are spread across countries or your host is slow to serve static files. Many optimisation plugins and hosts include a CDN option, and a whole-site CDN in front of WordPress caches the uploads folder without any plugin. Whatever you use, make sure images get a long cache lifetime, that only one layer converts formats, and that the CDN does not block search engine crawlers.

Audit your WordPress images

The Image Optimisation audit checks every image on your page for file size, format, dimensions, alt text, lazy-loading, layout shift and CDN delivery, and ranks its recommendations by their effect on loading and bandwidth.

Open Image Optimisation Fixes โ†’
๐Ÿ’ฌ Got a problem?
Related Guides: All Image Optimisation Fixes  ·  Core Web Vitals in WordPress  ·  Fixing Lazy Loading  ·  Fixing the Wrong Image Format  ·  Learning Hub

About aiwebpageseo

aiwebpageseo.com is a data-driven SEO and AEO (Answer Engine Optimisation) platform providing a free suite of technical SEO tools. Rather than relying on AI-theorised assumptions, the platform analyses live URL performance, delivering objective diagnostics, page speed metrics, CLS debugging, and site crawl data alongside actionable technical tutorials.