Skip to content
FunnelGuard

Fix guide by FunnelsGuard

GTM noscript iframe in head: why it breaks and how to fix it

TRK-104Low impactCould addBy FunnelGuardPublished Updated
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.

Correct placement of both GTM snippetshtml
<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.

What can go wrong when the head closes early
  • 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.
How a noscript iframe in the head changes the page
  1. GTM script in headLoads normally
  2. Noscript iframe in headNot valid in head
  3. Head closes earlyParser starts the body
  4. 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

Check the placement in two minutes
  1. 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.

  2. 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.

  3. 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.

  4. 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.

Move the noscript snippet by platform
  1. 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.

  2. 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_open hook. Your theme must call wp_body_open() after the opening body tag.

  3. 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.

Before and after the fix

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

Confirmation checks
  • View source shows the ns.html?id=GTM iframe 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

Habits that stop it coming back
  • 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.

Ways to watch for this issue
MethodCatches placement?Effort
View source search for ns.htmlYes1 minute
W3C Markup ValidatorYes2 minutes
GTM Tag AssistantNo, only that tags load2 minutes
FunnelGuard journey checksNo, only tracking effectsAutomatic 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.

Does FunnelGuard catch this?

Could add

Not checked yet: could be added to FunnelGuard.

Stop finding out from your customers

FunnelGuard runs your real forms and checkouts on a schedule, checks the tracking and the leads behind them, and alerts you once, with a screenshot. Try any paid plan free for 3 days.