Why Your WordPress Images Load the Wrong Size (And How to Fix It)
Content
Have you carefully selected an image size in the WordPress block editor, only to find your site loads a much larger file on the frontend? This is a common frustration that leads to slow page loads, especially on mobile devices. This guide will explain why it happens and walk you through the steps to fix it.
Why Does This Happen?
WordPress uses a responsive images technique. When you use core functions like the_post_thumbnail(), WordPress doesn't just output a single src attribute. It generates a srcset attribute—a list of all available image sizes for that attachment—and a sizes attribute that tells the browser how much space the image will take up on the page. The browser then chooses the most appropriate image from the srcset to download.
The problem occurs when your theme or a plugin interferes with this process. A lazy loading script, a custom image output function, or an incorrect sizes attribute can prevent the browser from making the correct choice, causing it to fall back to a larger, less optimal image.
How to Troubleshoot and Fix Incorrect Image Sizes
Step 1: Identify the Core Issue
First, you need to determine if the issue is with the theme or a plugin.
- Temporarily switch to a default WordPress theme like Twenty Twenty-One.
- Deactivate all your plugins.
Check your site's frontend again. If the correct image sizes now load, you know a theme or plugin is causing the conflict. Reactivate your plugins one by one, checking the site after each, to identify the culprit. If the problem persists with a default theme and no plugins, the issue may lie in your custom image size registration.
Step 2: Check Your Custom Image Size Registration
If you've added a custom image size in your theme's functions.php file, ensure it is correctly defined. A common mistake is not setting the fourth $crop parameter properly. For a hard-cropped thumbnail, it should look like this:
add_image_size( 'mini-thumb', 100, 100, true ); // True for hard crop
You must also remember to make your custom size available in the admin dropdown menu by using the image_size_names_choose filter, as shown in the sample threads.
Step 3: Verify Your Theme's Image Output
If you are hardcoding images in your theme files (e.g., header.php, footer.php) by copying the image URL from the media library, WordPress cannot automatically add the srcset and sizes attributes. You must explicitly use WordPress functions to get this benefit.
Instead of hardcoding, use functions like wp_get_attachment_image() which automatically handle responsive images. For example:
echo wp_get_attachment_image( $attachment_id, 'your-size-slug' );
Step 4: Consider Caching
If you've made changes to your image sizes or theme, a caching plugin or server-level cache might be serving an old version of the page. Clear all your caches after making any changes to see the results.
Conclusion
Images loading the wrong size is typically a conflict between WordPress's intelligent responsive image system and code from a theme or plugin. By systematically testing with a default theme, checking your custom code, and ensuring you're using WordPress's built-in image functions, you can resolve the issue and ensure your visitors get fast-loading, appropriately sized images.
Related Support Threads Support
-
[NSFW] What format should the images on my site be in?https://wordpress.org/support/topic/what-format-should-the-images-on-my-site-be-in/
-
Resetting Upload Itemhttps://wordpress.org/support/topic/resetting-upload-item/
-
WordPress breakpoint imageshttps://wordpress.org/support/topic/wordpress-breakpoint-images/
-
Preserve Image Metadatahttps://wordpress.org/support/topic/preserve-image-metadata-2/
-
Remove all scaled images and regenerate them with AVIFhttps://wordpress.org/support/topic/remove-all-scaled-images-and-regenerate-them-with-avif/
-
Anyway to know image sizes used and remove the unused?https://wordpress.org/support/topic/anyway-to-know-image-sizes-used-and-remove-the-unused/
-
Using image_editor_output_formathttps://wordpress.org/support/topic/using-image_editor_output_format/
-
2 questions about srcset function in wordpress?https://wordpress.org/support/topic/2-questions-about-srcset-function-in-wordpress/
-
How to upload resized images and associate them to the originalhttps://wordpress.org/support/topic/how-to-upload-resized-images-and-associate-them-to-the-original/
-
Can you programmatically set inline images to a new registered image size?https://wordpress.org/support/topic/can-you-programmatically-set-inline-images-to-a-new-registered-image-size/
-
Picture clicked, jumps to full size.https://wordpress.org/support/topic/picture-clicked-jumps-to-full-size/
-
Problems with media_sideload_imagehttps://wordpress.org/support/topic/problems-with-media_sideload_image/
-
wp_generate_attachment_metadata does not generate images with different sizeshttps://wordpress.org/support/topic/wp_generate_attachment_metadata-does-not-generate-images-with-different-sizes/
-
Convert get_option to inthttps://wordpress.org/support/topic/convert-get_option-to-int/
-
Customization option setting the same image for both mobile and desktophttps://wordpress.org/support/topic/customization-option-setting-the-same-image-for-both-mobile-and-desktop/
-
Unwanted compression of imageshttps://wordpress.org/support/topic/unwanted-compression-of-images/
-
Get file size, dimension and file type in image captionhttps://wordpress.org/support/topic/get-file-size-dimension-and-file-type-in-image-caption/
-
browser caching rules: enable caching mp4, jpghttps://wordpress.org/support/topic/browser-caching-rules-enable-caching-mp4-jpg/
-
OG:Image issuehttps://wordpress.org/support/topic/ogimage-issue-4/
-
Browsers load the wrong Image sizeshttps://wordpress.org/support/topic/browsers-load-the-wrong-image-sizes/
-
Replace multiple images at once, have them remained attached to posthttps://wordpress.org/support/topic/replace-multiple-images-at-once-have-them-remained-attached-to-post/
-
images bulk deletehttps://wordpress.org/support/topic/images-bulk-delete/
-
export featured imageshttps://wordpress.org/support/topic/export-featured-images-2/
-
Image over ride with automations processhttps://wordpress.org/support/topic/image-over-ride-with-automations-process/