Ads are one of the fastest ways to turn a technically valid AMP page into a jittery or policy-risky experience. The code itself is only two pieces; the careful work is making sure WordPress emits them once, in the AMP document—not merely the normal theme—and that consent, validation, performance, and publisher identity remain intact.
Before adding code
Your AdSense account and site must be approved/ready to serve ads.
The pages must actually render valid AMP documents; normal AdSense JavaScript is not a substitute on AMP.
Decide whether the site has paired AMP/non-AMP URLs or a single AMP canonical mode.
Review AdSense Program policies, Better Ads expectations, privacy disclosures, and regional consent obligations.
Back up WordPress and test on staging without allowing staging URLs to become indexable or canonical.
1. Pair AMP and non-AMP pages correctly
<link rel="amphtml" href="https://example.com/article/amp/">The normal page advertises its AMP alternative
rel="amphtml"points from the canonical non-AMP page to its corresponding AMP URL.Use an absolute HTTPS URL that returns the equivalent AMP content.
Do not point every article to one generic AMP landing page.
WordPress AMP plugins normally generate this relationship; inspect output before adding it manually.
<link rel="canonical" href="https://example.com/article/">The AMP alternative points back to the representative page
The paired AMP page normally canonicalizes to the non-AMP article.
In a single AMP-only Standard mode, the page can use a self-referential canonical according to the plugin/site architecture.
Canonical and amphtml relationships must match real equivalent content.
Keep sitemap, internal links, structured data, and redirects consistent with the chosen mode.
2. Enable Auto ads for AMP in AdSense
Sign in to the AdSense account that owns the approved publisher ID.
Open Ads and choose the AMP-site/Auto ads for AMP workflow shown in the current interface.
Turn on Auto ads for AMP and review each available ad format rather than enabling everything by reflex.
Choose Get AMP code and copy both snippets exactly from the account.
Apply the settings; serving can take time and depends on eligibility, inventory, policy, consent, traffic, and page structure.
3. Load the AMP Auto Ads component once
<script async custom-element="amp-auto-ads"
src="https://cdn.ampproject.org/v0/amp-auto-ads-0.1.js"></script>The extension script enables the custom element
asyncprevents the extension download from blocking HTML parsing.custom-element="amp-auto-ads"registers the AMP component declared in the body.The official AMP CDN URL and component version should match account-generated/current AMP documentation.
Include it once; duplicate extension scripts create invalid or noisy output.
Place it in the valid AMP head alongside the AMP runtime and required boilerplate.
4. Place the publisher element first in body
<body>
<amp-auto-ads
type="adsense"
data-ad-client="ca-pub-1234567890123456">
</amp-auto-ads>
<main>
<!-- Page content starts here. -->
</main>
</body>First child means first child
type="adsense"selects the AdSense network integration.data-ad-clientidentifies the publisher; use the exact ID issued to your account, not this example.The AMP component documentation requires
amp-auto-adsas the first child of body.Do not place it in a footer, inside article content, or once per ad position.
Auto ads chooses eligible placements subject to remote configuration and constraints; the element itself is not a visible ad slot.
WordPress: use an AMP-aware integration
Google recommends the AMP for WordPress plugin for creating AMP output and documents Standard, Transitional, and Reader template modes.
Google Site Kit can connect WordPress to AdSense and place code, including AMP/non-AMP support, when compatible with the chosen setup.
AdSense documents AMP-capable insertion options such as Advanced Ads, Ad Inserter, and certain header/footer insertion plugins; verify current compatibility before installation.
Use one owner for code insertion. Two plugins plus a theme snippet commonly duplicate scripts and publisher elements.
Prefer a child theme or plugin hook only when custom development is necessary and tested against generated AMP output.
Why direct theme-file edits are brittle
A theme update can overwrite
header.phporfooter.php.Reader/Transitional AMP templates may not render the same PHP files as the normal theme.
Placing the body snippet in a footer violates the required first-child placement.
Conditional logic can accidentally add AMP code to non-AMP HTML or standard AdSense code to AMP.
A child theme still requires AMP validation and lifecycle ownership; it is not automatically safe.
A safe custom-hook shape
<?php
/* Register with hooks exposed by your installed AMP integration.
* Hook names vary by plugin/version: consult its current documentation.
*/
function site_amp_auto_ads_head(): void {
// Escape/static output and emit once in the AMP document head.
}
function site_amp_auto_ads_body_start(): void {
// Emit account-generated amp-auto-ads as the first body child.
}The placeholder avoids inventing unstable hooks
This is architecture, not copy-paste production code; hook names depend on the installed AMP solution and version.
Keep integration in a small site plugin so theme changes do not own monetization.
Gate output to valid AMP responses and prevent duplicates.
Escape/configure publisher data through trusted administrative settings.
Add automated rendered-HTML tests around the selected real hooks.
Validate the generated AMP page
npx amphtml-validator https://example.com/article/amp/PASS means the fetched document satisfies the validator version used. Replace the example URL and review every reported error/warning.Validation checks the delivered document
Run against production-like output after WordPress, cache, CDN, consent, and ad plugins modify it.
npxdownloads/runs a package according to npm configuration; pin/audit tooling in CI rather than trusting an unreviewed transient version.A valid page can still have policy, consent, usability, performance, or revenue problems.
Validate representative templates: posts, pages, archives, embeds, logged-out views, and localized variants.
Re-run after plugin/theme/AMP runtime updates.
Inspect placement and duplication
curl -sS https://example.com/article/amp/ | rg -n "amp-auto-ads|data-ad-client|rel=\"canonical\""Expect one extension script, one publisher element near the opening body, the correct publisher ID, and a deliberate canonical URL.Source checks catch plugin collisions
Count both the script and body element; each should be emitted once.
Confirm cache/CDN responses match the WordPress origin after changes.
Do not paste full responses publicly when they include private preview data or personalized content.
Regex is a quick diagnostic; DOM-aware tests should enforce document order and attributes.
Check logged-out/incognito output because administrators may bypass ads or cache.
Consent and privacy come before ad requests
Determine which laws and Google consent policies apply to visitors in each region; obtain legal guidance where needed.
Use a consent management platform and AMP-compatible consent integration that can gate storage/ad behavior as required.
Google-certified CMP requirements may apply for AdSense traffic in the EEA, UK, and Switzerland; verify the current policy in your account/documentation.
Offer clear choices and preserve consent state/accessibility without dark patterns.
Test personalized, non-personalized/limited, denied, withdrawn, unknown, and returning-user flows.
Do not assume a WordPress cookie banner automatically controls AMP ad requests.
ads.txt and seller identity
google.com, pub-1234567890123456, DIRECT, f08c47fec0942fa0Copy the authorized-seller line from AdSense
Replace the publisher number with the account’s exact authorized value.
DIRECTversusRESELLERdescribes the account relationship and must not be guessed.Serve
ads.txtfrom the site’s root domain over a crawlable successful response.Redirect/domain/encoding mistakes can prevent retrieval.
Use AdSense account diagnostics and the IAB specification for current requirements.
Core Web Vitals and ad UX
Measure real-user LCP, INP, and CLS before and after enabling formats; lab tests alone do not prove field impact.
Avoid formats that obscure navigation, code, consent, or primary actions.
Auto placement still needs page-level exclusions and format/load tuning when UX suffers.
Reserve stable space for manually placed
amp-adunits and use valid responsive layouts.Do not place ads where accidental taps are likely or where they imitate content/navigation.
Compare revenue per session with retention, search performance, bounce, and page speed—not RPM alone.
Why ads may not appear
The account/site is pending, restricted, disabled, or has unresolved policy actions.
Auto ads for AMP is not enabled/applied in the correct AdSense account.
Publisher ID, script, or body element is missing, duplicated, or malformed.
The body element is not the first child or the AMP page is invalid.
Consent correctly prevents a request for that user/region/state.
The page has insufficient eligible placements, low content, excluded formats/pages, or no matching inventory.
Ad blockers, DNS filters, browser privacy features, cache, or network restrictions block requests.
ads.txt is missing/wrong, canonical/AMP pairing is broken, or the tested URL is not the generated AMP version.
New settings have not propagated; AdSense says ads can take time to appear.
Debug without clicking your own ads
Use browser developer tools to inspect validation, console, network requests, consent state, and layout shifts.
Test in an incognito logged-out session with extensions disabled, then separately with realistic privacy controls.
Never click live ads to test them or ask coworkers/users to click; invalid traffic can endanger the account.
Use publisher tools/test modes explicitly documented by Google where available.
Record time, URL, template, region/consent, device, response status, and screenshots without collecting personal data.
Launch checklist
AdSense/site readiness and current program/consent policies are reviewed.
AMP/non-AMP canonical relationships match the selected WordPress template mode.
One official component script is in head and one account-generated publisher element is first in body.
Only one plugin/integration owns insertion; direct parent-theme edits are removed.
AMP validation passes across representative templates and cache/CDN output.
Publisher ID and ads.txt are correct; no credentials are exposed.
Consent choices, accessibility, page exclusions, ad load/formats, Core Web Vitals, and real-user UX are tested.
Reporting uses the Content platform breakdown and monitoring covers policy, revenue, performance, retention, and invalid traffic.
Official references
Set up Auto ads on your AMP site provides the current AdSense account steps and exact placement requirements.
amp-auto-ads component defines its script, attributes, placement, constraints, and validation.
Insert ad code into AMP WordPress describes AMP plugin modes and supported insertion approaches.
Connect WordPress to AdSense documents Site Kit and AdSense integration considerations.
AdSense Program policies should be reviewed before monetization changes.
Comments and corrections