If you are using the official AMP plugin with WordPress 6.7 or newer, you may encounter this error when validating your AMP pages:
The attribute ‘style amp-custom’ in tag ‘style amp-custom’ is set to the invalid value…
The issue stems from invalid CSS selectors automatically inserted by WordPress into AMP pages. Specifically, selectors like:
The issue stems from invalid CSS selectors automatically inserted by WordPress into AMP pages. Specifically, selectors like:
<style amp-custom>
img:is([sizes=”auto” i], [sizes^=”auto,” i]) {
contain-intrinsic-size: 3000px 1500px;
}
</style>
The i flag inside attribute selectors is not valid AMP-compliant CSS, and causes your AMP pages to fail validation.
Let’s walk through all the ways to fix it, from safe and recommended to advanced and temporary.
✅ Recommended Fixes
1. Create a Custom Plugin to Disable Auto-Sizes in AMP
This is the safest and most future-proof method. You’ll disable the auto-sizes feature only for AMP requests, preventing the faulty CSS from being injected.
🔧 Steps:
-
Go to your website files via FTP, cPanel, or your local WordPress install.
Advertisement -
Navigate to:
wp-content/plugins/
-
Create a new file:
disable-amp-auto-sizes.php
-
Open it in a code editor and paste:
function amp_disable_img_auto_sizes() {<?php
/*
Plugin Name: Disable AMP Auto Sizes
Description: Disables auto sizes attribute on AMP pages to fix invalid CSS in WordPress 6.7+
Version: 1.0
*/
if ( function_exists( ‘amp_is_request’ ) && amp_is_request() ) {
return false;
}
return true;
}
add_filter( ‘wp_img_tag_add_auto_sizes’, ‘amp_disable_img_auto_sizes’ ); -
Save the file.
-
In your WordPress dashboard, go to Plugins > Installed Plugins and activate “Disable AMP Auto Sizes”.
-
Go to AMP > Tools > Purge AMP Cache to refresh old AMP pages.
-
Clear any page caching plugin or server cache (like LiteSpeed, WP Rocket, or Cloudflare).
✅ You’re done. AMP validation should now pass.
2. Use a Child Theme’s functions.php File
If you prefer not to create a plugin, you can add the same filter to your child theme’s functions.php file.
⚠️ Do not modify your main theme’s functions.php — changes will be lost during updates.
🔧 Steps:
-
Make sure a child theme is active. If not, install one. For Newspaper theme users, download the tagDiv child theme here.
-
Open:
wp-content/themes/tagdiv-child/functions.php
-
Add this code at the bottom:
function amp_disable_img_auto_sizes() {
if ( function_exists( 'amp_is_request' ) && amp_is_request() ) {
return false;
}
return true;
}
add_filter( 'wp_img_tag_add_auto_sizes', 'amp_disable_img_auto_sizes' );
-
Save and clear cache.
✅ This achieves the same effect but uses your theme instead of a plugin.
🛠️ Advanced (Not Recommended): Edit WordPress Core File
⚠️ Only for emergency use or experimentation. Not safe for production or future updates.
This method involves commenting out the line of code in WordPress core that inserts the invalid CSS.
🔎 How to Find the Code:
-
Go to:
wp-includes/media.php
-
Search for this line (introduced in WordPress 6.7.1):
$styles .= 'img:is([sizes="auto" i],[sizes^="auto," i]){contain-intrinsic-size:3000px 1500px}';
-
Simply comment it out:
// $styles .= 'img:is([sizes="auto" i],[sizes^="auto," i]){contain-intrinsic-size:3000px 1500px}';
-
Save the file, clear cache and test again.
✅ The CSS will no longer be injected.
❌ But: WordPress updates will overwrite this file, so this fix won’t last unless you repeat it after every update.
💬 Frequently Asked Questions
Q: Why is this CSS even there?
A: WordPress 6.7+ introduced automatic handling of <img sizes="auto"> to improve responsive images. The CSS is valid for normal browsers, but AMP does not support the i flag in selectors.
Q: Will disabling auto-sizes break images?
A: No, AMP already optimises image loading. Removing auto-sizes will not noticeably affect layout or performance.
Q: I’m using the Newspaper theme. Which functions.php should I use?
A: Only use the one inside your child theme. If you’re unsure, install the tagDiv Child Theme and activate it.
🧪 Test Your Fix
Use either of the following tools to re-test your AMP page:
🎉 Finally
The [sizes="auto" i] issue is a result of an update in WordPress that doesn’t fully account for AMP CSS limitations. While WordPress may resolve this in future versions, the above workarounds will help you maintain a clean, validated AMP setup in the meantime.
The best and safest way is to use a small custom plugin that disables auto-sizes only for AMP pages — no risk to your theme or core.
Let me know if you want a downloadable plugin ZIP version or if you’d like to publish this as a post with custom screenshots or code blocks.

