Automatic Image Dimensions adds the missing width and height attributes to images on your pages. With these attributes, the browser can reserve the right amount of space before an image loads, so text and buttons do not jump down when it appears.
Available in: Powered Cache Premium
Where to find it: Powered Cache → Media
Why it helps Cumulative Layout Shift #
Cumulative Layout Shift (CLS) is the Core Web Vital that measures how much content moves around while a page loads. An image without a size takes up no space until its file arrives, then pushes everything below it down. PageSpeed Insights reports this as “Image elements do not have explicit width and height”. When the size is in the HTML, modern browsers calculate the image’s aspect ratio in advance and keep the space free, even when CSS makes the image responsive.
Images you insert with the block editor already have a size. Missing sizes usually come from themes, page builders, widgets and HTML that was written by hand.
Turn on Automatic Image Dimensions #
- Go to Powered Cache → Media.
- Turn on Automatic Image Dimensions. Default: off.
- Click Save Settings and clear the cache so pages are rebuilt.
- Open a page in a private browser window, view the source and check that images now have
widthandheightattributes.
How it works #
Before a page is sent to the visitor (and saved to the page cache), Powered Cache looks for <img> tags that have neither a width nor a height attribute. For each one, it finds the image file on your server, reads its real size and adds both attributes. The work happens once per cached page, so it does not slow down cached visits.
An image is left unchanged when:
- it already has a
widthor aheightattribute, - it is stored on another domain, or its file cannot be found on your server,
- it is an SVG file,
- its
srcis a placeholder or inline data, for example an image that a lazy-load script, including Powered Cache Lazy Load, has replaced with a placeholder, - it has the
data-skip-image-dimensionsattribute.
Pages are not processed in the admin area, for previews, REST API requests and requests other than GET. Logged-in users get unprocessed pages unless Logged-in User Cache is on.
Changed in 4.0: Sizes are only added for images stored on your site. Earlier versions also downloaded remote images to measure them, which could slow down page generation.
Exclude an image #
If adding a size breaks the look of a specific image, add the data-skip-image-dimensions attribute to its tag:
<img src="/wp-content/uploads/banner.jpg" alt="" data-skip-image-dimensions>
For developers: the powered_cache_skip_adding_missing_image_dimensions filter receives false, the image address and the image tag. Return true to skip that image.
Troubleshooting #
An image looks stretched or the wrong size #
The attributes use the real size of the file. If your theme’s CSS sets only the width of an image and not height: auto, the browser can use the added height. Fix it in the theme CSS, or skip that image with data-skip-image-dimensions.
PageSpeed Insights still reports images without a size #
Check whether the listed images are on another domain, are SVG files or are lazy-loaded placeholders, which are skipped. Add the size to those images in your theme or page builder. Also clear the cache, because pages cached before you turned the option on are not updated.
Related docs #
- Lazy Load
- Image Optimization (Premium)
- LCP Optimization (Premium)
- Clear Cache