如何修复WordPress中AMP自动广告报错“Cannot resize element and overflow is not available”
Hey there, let’s work through this frustrating issue with your Google AdSense Auto-Ads for AMP. Those console errors (No anchor element found, Cannot resize element and overflow is not available) and the amp-ad tag stuck at height="0" give us some clear clues to follow. Here are targeted steps to resolve this:
1. Verify Your Page Content Structure
The No anchor element found error means AdSense can’t find valid spots in your content to place ads. AMP auto-ads rely on natural content anchors like paragraphs, headings, and section breaks to inject ads.
- Make sure your AMP page has enough structured content—avoid lumping all text into a single block or hiding content with CSS (like
display: none). - Check if dynamic content loading (like lazy-loaded sections) is delaying content rendering. AdSense needs content to be present when it scans the page, so try disabling lazy load for critical content blocks temporarily to test.
2. Correct Your amp-auto-ad Code Implementation
The height="0" issue suggests something’s off with how the auto-ad tag is being rendered:
- Double-check your
amp-auto-adcode—it should look like this (no manualheightattribute needed):<amp-auto-ad data-ad-client="ca-pub-YOUR_CLIENT_ID" type="adsense"></amp-auto-ad> - If you’re injecting the code via
functions.php, ensure it’s being added directly inside the<body>tag (not nested inside other elements like a container div that might restrict its visibility). - Avoid any custom CSS that might target
amp-auto-adoramp-adtags and forceheight: 0—check your theme’s stylesheet or custom CSS for conflicting rules.
3. Check Your AdSense Account & Auto-Ads Settings
Sometimes the problem isn’t with your site code, but with your AdSense configuration:
- Log into your AdSense dashboard and confirm AMP auto-ads are enabled for your domain.
- Verify your domain is properly verified in AdSense (even if it worked before, sometimes verification can glitch).
- Check for any policy warnings or account restrictions—these can block ads from showing without obvious on-site errors.
4. Audit AMP Plugin Output
Switching plugins might not have fixed underlying code placement issues:
- Use your browser’s DevTools to view the raw HTML of your AMP page. Confirm the
amp-auto-adtag is present in the<body>and not wrapped in invalid AMP elements (like<amp-iframe>or hidden containers). - Try manually adding the
amp-auto-adcode directly to your AMP theme template (instead of relying on plugin injection). This ensures the tag loads in the correct position without being filtered out by plugin logic.
5. Flush All Caches (Thoroughly)
Even if you cleared your site cache, residual caches might be causing issues:
- Clear your browser cache (use incognito mode to test without cached data) or do a hard refresh (
Ctrl+F5on Windows,Cmd+Shift+Ron Mac). - If you use a CDN, flush its cache too—old cached pages might not include your updated ad code.
- Double-check W3 Total Cache settings to ensure AMP pages are being cached correctly (or disable AMP caching temporarily to test).
6. Test in a Minimal Environment
Conflicts with your theme or plugins might still be lurking:
- Switch to a default WordPress theme (e.g., Twenty Twenty-Four) and deactivate all plugins except your AMP plugin and any essential ones.
- Test if ads show up in this minimal setup. If they do, reactivate your theme and plugins one by one to find the conflicting component.
内容的提问来源于stack exchange,提问作者fmkmasta

