How to add Google Tag Manager in WordPress without opening your theme

Google gave you two blocks. Put them in two snippets, not in header.php, Site Kit, or a one-job plugin.

Don’t open header.php. Don’t install a “GTM for WordPress” plugin. Don’t hope Site Kit already dropped both pieces for you.

Google Tag Manager still sends two blocks. One script they want at the top of every page. One noscript iframe they want just after the page starts. If you only paste the script, the install is incomplete.

I keep both in FluentSnippets. Two rows. Two off switches. A theme update cannot eat them.

When this is the wrong post

If Google sent you a measurement ID that starts with G-, you want the header and footer walk. That’s Analytics, one paste.

If Site Kit (or another plugin) already added Tag Manager, don’t paste a second copy. You’ll fire the container twice.

If you don’t have a container yet, make one at tagmanager.google.com first. Click the container ID. Copy both blocks. Keep them. You need both.

Then come back.

Install FluentSnippets

Get it from WordPress.org or from our get page.

In wp-admin go to Plugins → Add New. Search FluentSnippets. Click Install, then Activate.

No account. Open FluentSnippets in the left menu. You’re on the snippets list.

The header script is a contract, not a banner

Open FluentSnippets. You should see the list, even if it’s empty.

The FluentSnippets snippets list, with a dark New Snippet button in the upper right.
The snippets list. Look at the dark navy New Snippet button in the upper right. Click that.

Click New Snippet.

Create New opens. Functions (PHP) is already selected. That’s for PHP. The Tag Manager script is HTML, so switch to the green Content (PHP + HTML).

Create New Snippet. Functions (PHP) is selected by default. Content (PHP + HTML) is the green option. Snippet Name is on the right.
Create New. Look at the four types across the top. Functions (PHP) is selected. Click the green Content (PHP + HTML). Then look at the Snippet Name box on the right.

Name it GTM header. Description, group, and tags can wait.

Open Where to Run?.

The Where to Run list, showing Site Wide Header, Site Wide Body Open, and Site Wide Footer.
The Where to Run? list. Look at Site Wide Header. That's the hidden top of every page. Not the logo.

Click Site Wide Header.

Paste the first block Google showed you. That’s the script. If you’re following along, use this and swap every GTM-XXXXXX for your container ID. It always starts with GTM-.

<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-XXXXXX');</script>

Paste it as they sent it. Don’t wrap it.

Click Create Snippet. Check the paste. Publish it. You want the green published badge.

That’s the first snippet.

The noscript block sits just after the page starts

Go back to the snippets list.

The FluentSnippets snippets list, with a dark New Snippet button in the upper right.
Back on the list. Look at the dark navy New Snippet button again. A header tag sits in a group like Tracking. Google Analytics 4 is already there in this shot.

Click New Snippet again.

Same Create New screen. Functions (PHP) is selected again. Switch to green Content (PHP + HTML) again.

Create New Snippet. Functions (PHP) is selected by default. Content (PHP + HTML) is the green option.
Same Create New screen. Look at the green Content (PHP + HTML) option. Click it. Name this one *GTM noscript*.

Open Where to Run? again.

The Where to Run list, showing Site Wide Header, Site Wide Body Open, and Site Wide Footer.
The Where to Run? list again. This time look at Site Wide Body Open, not Header. That's just after the page starts. Not the footer, not the copyright line.

Click Site Wide Body Open.

Paste the second block. That’s the noscript iframe. Same container ID as the header snippet.

<noscript>
  <iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXXX"
          height="0" width="0" style="display:none;visibility:hidden"></iframe>
</noscript>

Click Create Snippet. Publish it.

You now have two rows. Header script. Body-open noscript. One list.

Old themes sometimes don’t have a slot “just after the page starts.” If Site Wide Body Open prints nothing, put the noscript in Site Wide Header so you don’t lose it. Not where Google asked. Better than missing.

Check both blocks on a public page

View source on a public page. The script should sit near the top of the page. The ns.html iframe should sit just after the page starts.

Then run Tag Manager Preview on that same URL. If Preview sees the container, you’re done.

When you want it off, open FluentSnippets and deactivate the row. You don’t have to remember which theme file you touched.

How to add header and footer code without editing your theme if you only have a G- tag. Official install notes: Install a web container.

Enjoyed this? Get the next one by email.

New articles, practical snippets and feature walkthroughs — sent when there's something worth reading, not on a schedule.

No spam, no selling. Unsubscribe anytime.

Custom code, without the database.

FluentSnippets is free on WordPress.org. Zero queries, no lock-in.