On this page
What this issue is
Google Tag Manager (GTM) gives you two code snippets to install. The first is a JavaScript snippet that goes as high as possible in the <head>. The second is a <noscript> fallback containing an iframe. It goes immediately after the opening `<body>` tag.
This issue happens when the second snippet is pasted into the head too. It often happens when someone pastes both snippets into one 'header scripts' box in a theme, page builder or plugin.
The noscript fallback only matters for visitors with JavaScript turned off. The real danger is a side effect. An <iframe> is not valid inside <head>, so the browser's HTML parser treats it as the start of the body. It closes the head early. Anything placed after it in your head, such as meta tags, canonical links, stylesheets or other scripts, can end up in the body instead.
<head>
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXXXXX');</script>
<!-- End Google Tag Manager -->
</head>
<body>
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXXXX"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->Why it costs you leads or sales
The business impact is usually low. Most visitors run JavaScript, so the main GTM tag still loads and your tags still fire. The cost comes from what the early head close can break.
- Meta tags, canonical links or hreflang placed after the iframe move into the body and may be ignored by search engines.
- Other scripts or stylesheets after the iframe load in a different order than you planned.
- Tag or consent scripts that must run early may run later than intended.
- HTML validators and some audit tools report the page as invalid.
- The noscript fallback itself may not work as intended for visitors without JavaScript.
- GTM script in headLoads normally
- Noscript iframe in headNot valid in head
- Head closes earlyParser starts the body
- Later meta, canonical, scriptsNow sit in the body
The parser closes the head at the iframe, so later head tags land in the body.
How to check if your site has it
View the raw source
Open your page, press Ctrl+U (Cmd+Option+U on Mac) and search for
ns.html?id=GTM. Note whether it appears before or after the<body>tag.Compare with the rendered DOM
Open DevTools, go to Elements and expand
<head>. If you see meta tags or scripts you placed in the head sitting inside<body>, the head closed early.Check Tag Assistant
Open tagassistant.google.com, connect your page and confirm the container loads. This shows the main tag works, but not the noscript placement, so still check the source.
Run an HTML validator
Paste the URL into the W3C Markup Validator. An iframe in the head is reported as an error.
How to fix it
The fix is the same everywhere: keep the JavaScript snippet in the head and move the noscript block to just after the opening body tag. How you do that depends on your platform.
Find where it was added
Check your GTM plugin (for example Site Kit or GTM4WP), a header-scripts plugin, or your theme's header.php.
Use a body-open hook
Remove the noscript from the head field. Paste it in a 'body open' field if your plugin has one, or add it via the
wp_body_openhook. Your theme must callwp_body_open()after the opening body tag.Or let a plugin do it
Plugins like GTM4WP place both snippets correctly from just the container ID. Remove your manual copies to avoid duplicates.
Edit theme.liquid
Go to Online Store > Themes > Edit code and open
layout/theme.liquid.Move the block
Delete the noscript from inside
<head>and paste it directly after the<body>opening tag.Save and test
Reload a product page and check the source again.
Copy fresh code
In GTM, click your container ID (GTM-XXXXXXX) at the top of the workspace. The install dialog shows both snippets with placement notes.
Install each in its place
Paste the first into the head and the second right after
<body>. GTM itself cannot move code on your site.
Open custom code
Go to Site settings > Custom code. The 'Head code' box is for the script only.
Move the noscript
Remove it from Head code and paste it into 'Footer code' only if you accept late placement. For strict placement, add an Embed element at the very top of the body on each page or in a symbol used on every page.
Open tracking code settings
In your funnel or website settings, find 'Header tracking code' and 'Body tracking code' (names can vary by version).
Split the snippets
Keep the script in the header box and move the noscript to the body box.
Use the Google Tag Manager integration
In Marketing integrations, connect Google Tag Manager with your container ID so Wix places the code itself.
Remove manual copies
If you added custom code under Settings > Custom code, delete the noscript block there to avoid duplicates.
Check Code Injection
Settings > Advanced > Code Injection has Header and Footer boxes only. There is no box right after the body tag.
Remove the noscript from Header
Keep the script in Header. The noscript is optional, so leaving it out is safer than keeping it in the head. If your template allows editing, add it right after
<body>.
Edit your base template
Open the layout file shared by all pages (for example
layout,base.htmlor_document).Move the block
Place the noscript as the first child of
<body>, then deploy.
Noscript in head
- Iframe sits between head tags
- DOM shows head tags inside body
- Validator reports an error
Noscript after body tag
- Head contains only valid elements
- Meta and canonical stay in the head
- Validator passes this check
How to confirm it's fixed
- View source shows the
ns.html?id=GTMiframe after the opening<body>tag. - Only one GTM script and one noscript block appear per page.
- DevTools Elements shows your meta tags and canonical link inside
<head>. - The W3C validator no longer reports an iframe in the head.
- Tag Assistant still shows the container loading and your tags firing.
- Check a few page types: home, product, form and thank-you pages.
How to prevent it happening again
- Install GTM with one trusted method per site, not several.
- When you paste both snippets, use separate head and body fields.
- After theme updates or migrations, re-check the page source.
- Add the placement to your launch checklist for new pages and templates.
- Document who owns the GTM install so agencies do not add a second copy.
How FunnelGuard handles this
FunnelGuard does not check noscript placement today. It is a possible future check. FunnelGuard is a synthetic monitoring service: a robot visitor runs your real customer journeys on a schedule and checks each step and the tracking hits sent to GA4, Google Ads, Meta and other platforms.
That helps with the effects that matter most. If a misplaced snippet ever stopped GTM from loading or a tag from firing, a journey check would show the missing tracking hit. It would not tell you the cause is the noscript position.
To watch for this yourself, re-run the source check after each theme or plugin change, and run the W3C validator on your key templates. A free read-only FunnelGuard website audit is also available, and the Free plan covers 1 site and 2 journeys with daily checks, no card needed.
| Method | Catches placement? | Effort |
|---|---|---|
| View source search for ns.html | Yes | 1 minute |
| W3C Markup Validator | Yes | 2 minutes |
| GTM Tag Assistant | No, only that tags load | 2 minutes |
| FunnelGuard journey checks | No, only tracking effects | Automatic once set up |
Questions people ask
Where should the GTM noscript code go?
Place it immediately after the opening <body> tag, as high as possible in the body. The main JavaScript snippet goes in the <head>. Google's install dialog in GTM shows both with these placement notes.
Can I put the GTM noscript iframe in the head?
You should not. An iframe is not valid in the head, so browsers can close the head early and move later tags into the body. That can affect meta tags, canonical links and script order.
Does the noscript in the head stop GTM tags from firing?
Usually not. The main script in the head still runs for visitors with JavaScript, so tags normally fire. The harm is mostly to the page structure and anything placed after the iframe in the head.
How do I check where my GTM noscript is placed?
Open the page source with Ctrl+U and search for ns.html?id=GTM. See whether it comes before or after the <body> tag. Then check DevTools Elements to see whether your head tags moved into the body.
Do I need the GTM noscript tag at all?
It is recommended but optional in practice. It only serves visitors who have JavaScript disabled. If your platform cannot place it after the body tag, leaving it out is better than keeping it in the head.
Why does my HTML validator say an iframe is not allowed in head?
The HTML spec does not allow iframes in the head, and the GTM noscript contains one. Moving the noscript block to just after the opening body tag clears the error.
Will moving the noscript hurt my tracking?
No. Moving it into the body is the supported setup. After the change, confirm with Tag Assistant that the container still loads and your tags still fire.
Related issues
- TRK-099GTM container snippet missingFix guide
- TRK-101Two GTM containers fighting (old agency + new)Fix guide
- TRK-105GTM snippet placed in footer, firing lateFix guide
- TRK-100Wrong GTM container ID on siteFix guide
- TRK-102GTM container published version changed unexpectedlyFix guide
- TRK-103Workspace changes never published (tag in preview only)Fix guide