Created
February 10, 2026 20:24
-
-
Save joemaller/8f9b2b411cf4056076a07021d69704fd to your computer and use it in GitHub Desktop.
Prevent WordPress 6.7's auto-size feature from showing missing images at enormous sizes that break layouts.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * WordPress 6.7 introduced an inline style rule which can cause missing images to render at | |
| * huge sizes, breaking layouts. There are three possible solutions: | |
| * | |
| * 1. Add a filter to disable auto sizes entirely: | |
| * | |
| * add_filter( 'wp_img_tag_add_auto_sizes', '__return_false' ); | |
| * | |
| * 2. Add this style rule to the frontend CSS somewhere: | |
| * | |
| * img[sizes*="auto"][src]:not([src^="data:"]) { max-height: 100%; } | |
| * | |
| * 3. Dequeue the style: | |
| * | |
| * add_action( 'wp_enqueue_scripts', function() { | |
| * wp_dequeue_style( 'wp-img-auto-sizes-contain' ); | |
| * }, 20 ); | |
| */ | |
| add_filter( 'wp_img_tag_add_auto_sizes', '__return_false' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment