How to Add Google Tag Manager to WordPress (2026 Guide)

Add Google Tag Manager to WordPress — laptop showing a website analytics dashboard

Every tracking script you add to WordPress — Google Analytics, the Meta Pixel, a heatmap tool, a chat widget — is another snippet pasted into your theme, another thing to maintain, and another chance to break something. Google Tag Manager (GTM) ends that cycle. When you add Google Tag Manager to WordPress, you install one container on your site, and from then on you add, edit, and remove every tracking tag from GTM’s dashboard instead of touching your code. This guide covers the whole setup: creating your container, installing it, connecting Google Analytics 4, and testing in Preview mode.

What Is Google Tag Manager — and What It Isn’t

Google Tag Manager is a free tag management system from Google. You place one piece of code — a container — on your website, and it loads whatever tags you configure inside GTM: analytics, advertising pixels, conversion tracking, and more. Every change is saved as a version you can roll back.

Get one thing straight first: GTM is not Google Analytics. On its own it collects nothing — it is a delivery system, and a container with no tags measures nothing. That is its strength: install GTM once, and every future tracking change happens in GTM, not in your theme files.

Before You Start: What You Need

You need three things before you begin:

  • WordPress admin access — you will install a plugin or add a small code snippet.
  • A Google account that should own the tracking. Use a company-controlled account, not a freelancer’s personal one.
  • A Google Analytics 4 property and its Measurement ID (G-XXXXXXXXXX) if you want Analytics running through GTM.

Decide on one installation method before you start: GTM must be installed exactly once, or every event is counted twice.

Step 1: Create Your GTM Account and Container

  1. Go to tagmanager.google.com and sign in with the Google account that should own the tracking.
  2. Click Create Account, name it after your business, and select your country.
  3. Under Container setup, enter your domain as the container name and choose Web as the target platform.
  4. Accept the terms. GTM shows you two code snippets and your container ID, which looks like GTM-XXXXXXX. Keep the tab open.

If you close the tab, find the snippets again under Admin > Install Google Tag Manager. They are not interchangeable: the first is a script that goes as high in the <head> as possible, and the second is a <noscript> iframe that goes immediately after the opening <body> tag.

Step 2: Add Google Tag Manager to WordPress

Four reliable methods install GTM on WordPress. They all place the same two snippets on every page, so pick one and use only that one.

Method 1: GTM4WP Plugin (Recommended for Most Sites)

GTM4WP (listed as “Google Tag Manager for WordPress”) is the most capable option, and the one I recommend for most sites:

  1. In WordPress, go to Plugins > Add New and search for GTM4WP.
  2. Click Install Now, then Activate.
  3. Go to Settings > Google Tag Manager, paste your container ID in the Google Tag Manager ID field, set Container code ON/OFF to On, and save.

The plugin places both snippets correctly and pushes post type, author, category, search terms, and full WooCommerce purchase data into the data layer. If you run a WooCommerce store, this is the method to choose.

Method 2: Site Kit by Google

Site Kit is Google’s official WordPress plugin. Install it from Plugins > Add New, run the setup wizard and connect your Google account, then go to Site Kit > Settings > Connect more services > Tag Manager, select the container that matches your domain, and save.

Site Kit adds the snippets for you with no code involved. But watch out: if Site Kit also connects Analytics directly, and your GTM container contains a GA4 tag, every pageview is counted twice. Pick one path — either Site Kit handles GA4, or GTM does. To compare the two approaches, see my guide on how to add Google Analytics to WordPress.

Method 3: WPCode (Header and Footer Fields)

If you prefer manual placement without editing theme files, WPCode (formerly Insert Headers and Footers) is a clean middle ground. Install and activate WPCode, go to Code Snippets > Header & Footer, paste the first GTM snippet (the script) into the Header field and the second snippet (the <noscript> iframe) into the Body field, then save. It adds no data layer extras like GTM4WP, but it keeps the code out of your theme entirely.

Method 4: Manual Code in a Child Theme

If you are comfortable with a little PHP, you can add GTM with two WordPress hooks and no plugin. This belongs in a child theme — never paste code into a parent theme file, because the next update will wipe it out.

The head snippet hooks onto wp_head at priority 1, so GTM loads as early as possible. The body snippet hooks onto wp_body_open (WordPress 5.2+), which places it immediately after the opening <body> tag:

function amaardev_gtm_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 -->
<?php
}
add_action( 'wp_head', 'amaardev_gtm_head', 1 );

function amaardev_gtm_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) -->
<?php
}
add_action( 'wp_body_open', 'amaardev_gtm_body' );

Replace GTM-XXXXXXX with your real container ID in both places. One gotcha: wp_body_open only fires if your theme calls it. If yours is older, copy header.php into your child theme and add <?php wp_body_open(); ?> directly after the opening <body> tag.

Step 3: Add GA4 Through Google Tag Manager

With the container installed, the most useful first tag is Google Analytics 4. In the current GTM interface there is no separate “GA4 Configuration” tag type — you add a single tag called Google Tag:

  1. In GTM, go to Tags > New and name it something clear, like “GA4 – Pageviews”.
  2. Choose Google Tag and enter your GA4 Measurement ID (G-XXXXXXXXXX) as the Tag ID.
  3. Under Triggering, choose Initialization – All Pages. Then save.

Before you go further, remove any other GA4 installation — a Site Kit connection, a theme option, or a pasted gtag.js snippet. Two GA4 installs means double-counted pageviews.

Step 4: Test in Preview Mode, Then Publish

Nothing in GTM goes live until you publish the container — which is exactly why Preview mode exists:

  1. In GTM, click Preview and enter your website address. A new tab opens your site with a “Tag Assistant Connected” badge.
  2. In the debug window, look for Container Loaded and check that your Google Tag fired on the pageview event.
  3. Go back to GTM and click Submit to publish the container, giving the version a clear name like “GA4 pageview tag”.

This step is where most people lose a week of data: Preview only shows what would happen. Until you click Submit, visitors get nothing. Once published, check your GA4 Realtime report — you should see yourself within a minute or two. Standard reports can take 24–48 hours to fill in. And if Preview shows nothing firing, test in a clean browser profile first: ad blockers commonly block gtm.js.

Common Mistakes to Avoid

  • Installing GTM twice — a plugin plus a manual snippet, or Site Kit plus GTM4WP, double-counts everything.
  • Running GA4 both ways. GA4 through GTM plus GA4 through Site Kit or a theme setting double-counts every pageview.
  • Forgetting to hit Submit. Tags do nothing until the container version is published.
  • Pasting code into the parent theme. A theme update deletes it silently.
  • Putting the body snippet in the wrong place. The <noscript> iframe belongs immediately after the opening <body> tag — not in the head or footer.
  • Ignoring consent rules. In the EU or UK, GTM does not exempt you from cookie consent — pair it with Consent Mode.

Frequently Asked Questions

Is Google Tag Manager free?

Yes — free, with no pageview or tag limits. Google also sells GTM 360 for enterprises, but small and medium sites never need it.

Will GTM slow down my site?

The container script is small and loads asynchronously, so its direct impact is minimal. In practice GTM often speeds things up by replacing several separately loaded scripts with one container. The real risk is tag bloat — audit it regularly and delete tags you no longer use.

Conclusion

Now you know how to add Google Tag Manager to WordPress: create your container, install it once with GTM4WP, Site Kit, WPCode, or a few lines of code in a child theme, add your GA4 tag, test in Preview mode, and hit Submit. The whole job takes about fifteen minutes, and it pays for itself the first time someone asks for a new pixel. For a second reference on the same four methods, Jetpack’s guide to adding GTM to WordPress is worth a read.

If you would rather have a developer handle the setup — GTM, GA4, Search Console verification, and conversion events — get in touch through my contact page and I will set it up for you. To verify your site in Search Console with the same GTM install, my guide on how to add Google Search Console to WordPress covers that next step.