Adding Google Tag Manager to WordPress sounds like a five minute job: copy two snippets, paste them, done. Then you open Preview mode, and nothing fires. Or GA4 counts every pageview twice. Or the container works on desktop and vanishes behind your caching plugin.
This guide walks through the full setup from container creation to verification, and then spends serious time on the part most tutorials skip: the WordPress-specific conflicts that silently break GTM tracking. If you can follow a numbered list, you can do this.
Quick answer: how do I add Google Tag Manager to WordPress?
- Create a free Google Tag Manager account and a Web container for your domain.
- Copy the two snippets Google gives you (one for
<head>, one right after the opening<body>tag). - Install them with a plugin (GTM4WP or Site Kit) or manually through your child theme’s
functions.php. - Build your first tag inside GTM (usually a GA4 configuration tag).
- Click Preview, confirm the tags fire, then click Submit to publish the container.
Step 5 is where most people lose a week of data. More on that below.

What Google Tag Manager actually does on a WordPress site
Google Tag Manager is a free container that sits on your site and loads other scripts on demand. Instead of editing your theme every time marketing asks for a new pixel, you add it once inside GTM and publish. eseospace.com has a solid rundown on this.
On a WordPress site, that typically means managing:
- GA4 configuration and event tags
- Google Ads conversion tracking and remarketing
- Meta, LinkedIn, TikTok and Pinterest pixels
- Heatmap and session recording tools (Hotjar, Clarity, Matomo)
- Custom events: form submissions, scroll depth, outbound clicks, WooCommerce purchases
- Consent signals through Google Consent Mode
The trade-off: one more layer to debug. That is exactly what the troubleshooting section of this guide is for.
Before you start: a 2 minute checklist
- You have Administrator access to the WordPress site.
- You have a recent backup (or a staging site) if you plan to edit theme files.
- You know whether your theme already injects a GA4 or Universal tag somewhere in its options panel. Check this now, it prevents double tracking later.
- You are logged into the Google account that should own the container. Use a company account, not a freelancer’s personal Gmail.

Step 1: Create your Google Tag Manager account and container
- Go to tagmanager.google.com and sign in.
- Click Create Account.
- Account name: your company name. Country: where the business is based.
- Container name: your domain, for example
kingcontentagency.com. - Target platform: choose Web.
- Accept the terms. Google immediately shows you a modal with two code blocks and your GTM-XXXXXXX container ID.
Keep that modal open, or find it again later under Admin > Install Google Tag Manager.
One container per site, or one for all?
Use one container per website in almost every case. One account can hold many containers. Sharing a single container across several domains makes triggers messy and risks firing the wrong pixel on the wrong brand. The exception is a multi-site network where every property genuinely shares identical tracking. wpbuffs.com has a solid rundown on this.
Step 2: Understand the two snippets
Google gives you two blocks of code and they do different jobs.
| Snippet | Where it goes | What it does | Required? |
|---|---|---|---|
| Main JavaScript snippet | As high as possible inside <head> |
Loads the container, creates the dataLayer, fires your tags | Yes |
<noscript> iframe snippet |
Immediately after the opening <body> tag |
Fallback for visitors with JavaScript disabled | Optional in practice, but recommended for completeness |
Here is what they look like (replace GTM-XXXXXXX with your own ID):
Head snippet
<!-- 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 -->
Body snippet
<!-- 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) -->
Important: the two snippets must use the same container ID. Copy-paste errors between staging and production containers are a classic cause of “my tags fire in preview but not live”.

Step 3: Plugin or manual installation?
This is the question that fills Reddit threads. Both approaches put the same container on your site. The difference is what you get around the snippet.
| Method | Best for | Pros | Cons |
|---|---|---|---|
| GTM4WP plugin | WooCommerce stores, lead gen sites, anyone who wants rich data | Pushes post type, author, category, logged-in status, search terms, form events and full ecommerce data into the dataLayer automatically | One more plugin to maintain; settings can be overwhelming at first |
| Site Kit by Google | Beginners who also want Search Console and GA4 data in the dashboard | Official, guided setup, connects several Google products at once | No custom dataLayer variables; easy to end up double-tagging GA4 |
| Manual (child theme) | Lean sites, developers, strict performance budgets | Zero plugin overhead, full control over placement | No automatic dataLayer; breaks if you later edit theme files carelessly |
Option A: Install with the GTM4WP plugin (recommended for most sites)
- In WordPress go to Plugins > Add New and search for GTM4WP (listed as “Google Tag Manager for WordPress”).
- Install and activate it.
- Go to Settings > Google Tag Manager.
- Paste your container ID in the Google Tag Manager ID field.
- Under Container code ON/OFF, set it to On.
- Choose a container code placement. Start with Custom (manual coding required) only if you know what you are doing; otherwise pick Footer of the page or Codeless injection depending on your theme. The
body openoption is cleanest when your theme supports it. - Open the Integration and Basic data tabs and enable only what you will actually use: post data, search data, WooCommerce, form plugins.
- Save changes.
The big win here is the dataLayer. Without it you can only track clicks and URLs. With it you can build a trigger like “fire this tag only on posts in the Pricing category, by author X, for logged-out users” without writing a line of code.
Option B: Install with Site Kit by Google
- Install Site Kit by Google from the plugin repository.
- Run the setup wizard and connect your Google account.
- In Site Kit, go to Settings > Connect more services > Tag Manager.
- Select the container that matches your domain and save.
Warning: if Site Kit also connects Analytics directly, and your GTM container contains a GA4 tag, you will send every pageview twice. Pick one path: either Site Kit handles GA4, or GTM does. Not both.
Option C: Add Google Tag Manager to WordPress without a plugin
Never paste code into a parent theme file. A theme update will wipe it. Use a child theme or a code snippets plugin instead.
Add this to your child theme’s functions.php:
// GTM head snippet
add_action('wp_head', 'kca_gtm_head', 1);
function kca_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 }
// GTM body snippet
add_action('wp_body_open', 'kca_gtm_body', 1);
function kca_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 }
Two things to check:
- Your theme must call
wp_body_open()inheader.php. Most modern themes do. If yours does not, the noscript block will never appear, which is not fatal but worth knowing. - If you use a code snippets plugin instead, make sure the snippet is set to run on the front end only, not in the admin area.
What about Elementor, Divi and page builders?
Elementor Pro has Site Settings > Custom Code, where you can add the head snippet with location <head> and the noscript snippet with location Body (start). Divi has a similar field under Divi > Theme Options > Integration. These work fine, but they tie your tracking to the builder. If you ever migrate, the container disappears with it. A plugin or child theme is more portable.
Step 4: Create your first tag inside GTM
The container alone does nothing. It is an empty box until you add tags.
To add GA4:
- In GTM click Tags > New.
- Tag Configuration: choose Google Tag.
- Enter your GA4 Measurement ID (format
G-XXXXXXXXXX, found in GA4 under Admin > Data Streams). - Triggering: choose Initialization – All Pages.
- Name it something readable like GA4 – Base Config and save.
Before you go further, remove any other GA4 code from your site: theme options fields, Site Kit’s Analytics module, standalone analytics plugins. One GA4 tag, one location.

Step 5: Verify everything with Preview mode
This is the step that separates a working setup from a guess.
- In GTM click Preview (top right).
- Tag Assistant opens. Enter your site URL and click Connect.
- A new tab opens with your site and a “Tag Assistant Connected” badge.
- Switch back to the Tag Assistant tab. You should see a left column of events: Consent Initialization, Initialization, Container Loaded, DOM Ready, Window Loaded.
- Click an event and check the Tags Fired section. Your GA4 tag should be listed there.
- Browse a few pages, submit a test form, add a product to cart. Watch new events appear in real time.
- Cross-check in GA4 under Reports > Realtime. Seeing yourself there confirms data is actually arriving, not just that the tag claims to have fired.
Then publish. Seriously, publish.
Preview mode only affects your browser. Until you click Submit > Publish in the top right of GTM, no visitor is being tracked. This single forgotten click is responsible for more missing data than every technical bug combined.
Troubleshooting: common WordPress conflicts that break GTM
Tags not firing? Work through this table before you blame Google.
| Symptom | Likely cause | Fix |
|---|---|---|
| Tag Assistant will not connect at all | Page caching serving an old HTML version without the snippet | Purge the cache in your caching plugin and at CDN level, then retry |
| Container loads for admins only | Cache serves a cached page to logged-out users, generated before you installed GTM | Clear cache, then test in an incognito window |
| GTM script appears in source but never executes | JavaScript minification, combining or delay JS execution features | Exclude googletagmanager.com and the inline GTM snippet from minify, combine and delay rules |
| Works locally, breaks behind Cloudflare | Rocket Loader rewriting inline scripts | Disable Rocket Loader or add data-cfasync="false" to the snippet |
| Tags show as “not fired” with a consent warning | Cookie banner blocking tags until consent, or Consent Mode misconfigured | Accept cookies in the test window; check consent settings on each tag in GTM |
| Every pageview counted twice in GA4 | GA4 installed in both GTM and a plugin or theme option | Search your page source for gtag and G- and remove the duplicate source |
| Two containers loading | Snippet added manually and by a plugin | Search the source for GTM- and keep only one instance |
| Noscript snippet missing | Theme does not call wp_body_open() |
Add the hook to the child theme’s header.php or switch GTM4WP placement mode |
| Nothing tracked on your own visits | Ad blocker or privacy browser extension | Test in a clean browser profile with extensions disabled |
| Requests blocked after a security plugin update | Firewall or Content Security Policy headers | Allow googletagmanager.com and google-analytics.com in your CSP |
| Form submission events never fire | Form plugin uses AJAX, so no real form submit event occurs | Enable the form integration in GTM4WP or use a Custom Event trigger on the plugin’s own dataLayer push |
| Data appears in Preview but not in reports | Container never published | Click Submit > Publish in GTM |
A reliable 4 step debugging routine
- View page source (Ctrl+U) on a logged-out page and search for
GTM-. Zero results means the snippet is not being output. Two results means you have a duplicate. - Open DevTools > Network, filter on
gtm.js. A 200 response means the container loads. Nothing means something is blocking it. - Type
dataLayerin the Console. An array means the dataLayer exists.undefinedmeans the head snippet failed or was stripped. - Use Tag Assistant to check which trigger fired and which did not, tag by tag.

Good habits once GTM is live
- Name tags consistently: Platform – Type – Detail, for example GA4 – Event – Contact Form Submit.
- Write a version note on every publish. Future you will need to know what changed and when.
- Use a workspace per project when several people work in the same container.
- Audit quarterly: pause tags for tools you no longer pay for. Dead pixels still cost loading time.
- Set up Consent Mode v2 if you have EU or UK traffic. Most major WordPress consent plugins now support it natively.
- Consider server-side GTM if browser tracking loss is hurting your ad reporting. It is more work and more cost, but it is now a mainstream option rather than an experiment.
Frequently asked questions
Is there a Google Tag Manager plugin for WordPress?
Yes, several. The most capable is GTM4WP (Google Tag Manager for WordPress), which adds the container plus a detailed dataLayer. Site Kit by Google is the official Google plugin and can also install your container. Many SEO and consent plugins include a GTM field too, so check before stacking plugins.
Do I need a plugin, or can I add the code manually?
Manual installation works perfectly and adds no plugin overhead. Use a child theme so updates do not erase your code. Choose a plugin if you want automatic dataLayer variables such as post category, author, logged-in status or WooCommerce ecommerce data, which would otherwise require custom development.
Is Google Tag Manager still relevant?
Yes. It remains the standard way to deploy and govern marketing tags, and it is the backbone for Consent Mode and server-side tagging setups. Google continues to invest in it, and most analytics implementations in 2026 still run through a GTM container.
Where do I find my Google Tag Manager ID?
It is displayed at the top of your container workspace, formatted as GTM-XXXXXXX. You can also reach it via Admin > Install Google Tag Manager, which shows both snippets again.
Will Google Tag Manager slow down my WordPress site?
The container itself is small and loads asynchronously. The slowdown comes from what you put inside it. Five heavy third party scripts firing on every page will hurt your Core Web Vitals regardless of how they were installed. Fire tags only on the pages where they are needed and remove the ones you no longer use. Google Tag Manager for WordPress tracking and usage covers this in more depth.
Can I use Google Tag Manager and GA4 together?
Yes, and that is the recommended setup: GTM delivers the GA4 tag. Just make sure GA4 is installed in one place only. Running the GA4 snippet in your theme and a GA4 tag in GTM inflates sessions and destroys conversion accuracy.
Why do my tags work in Preview but not for real visitors?
Three usual suspects, in order of frequency: the container was never published, caching is serving older HTML to logged-out visitors, or a consent banner blocks tags until a visitor accepts cookies. Test in incognito after purging all caches.
Need this done properly?
A clean Google Tag Manager setup on WordPress takes about an hour. A broken one can quietly cost you months of unusable data and misreported ad spend. If you would rather have the container, dataLayer, GA4 events and consent configuration audited and built for you, get in touch with our team and we will handle the implementation end to end.
