# How to Add Google Tag Manager in WordPress Step by Step

_2026-11-13_

The container ID goes in, the tags fire, Tag Assistant connects, and the job looks done. Then someone asks the awkward question: which of those tags had permission to fire before the visitor touched the cookie banner.

That's where most Google Tag Manager in WordPress work begins. Installing the container is a twenty-minute task. Deciding what's allowed to run inside it, in what order, and with what evidence is the part that separates a clean measurement setup from a compliance problem nobody notices for eight months.

A container loading on every page proves exactly one thing: the snippet rendered. It doesn't prove that analytics waited, that an ad tag respected a rejection, or that a purchase counted once. Those are separate questions, and each one has its own test.

This guide covers the install routes first, then the consent defaults that have to sit above the container, then the verification sequence I'd run before any version gets published. The install is the easy half. The other half is what keeps the numbers trustworthy.

## Ways to Add Google Tag Manager to WordPress

Start with the account, not the plugin. You need a Google account, a Tag Manager account, and a **Web** container inside it, because Web is the only container type that produces the **GTM-XXXXXX** ID a WordPress site can consume. Every route below ends with that same ID.

GTM is the default rather than one option among several. [W3Techs](https://w3techs.com/technologies/details/tg-google) records it on **99.6% of websites whose tag-manager technology is known** and on **44.7% of all websites** in its monitored web sample, which is why plugins, theme snippets and agency handovers all assume it.

Three routes cover almost every WordPress site, and each fails in a different way.

| Method | Best for | Typical setup time | Main risk |
| --- | --- | --- | --- |
| Dedicated GTM plugin | Non-developers and most small sites | 10-15 minutes | Plugin settings can add tags outside the container |
| Child theme header code | Developers and custom themes | 20-30 minutes | Edits are lost on theme update if no child theme is used |
| Code snippets plugin | Quick changes without editing theme files | 10-15 minutes | Snippets become hard to audit as the site grows |

The warning that matters most: never edit the parent theme's `header.php`. A theme update replaces that file, the container disappears from the rendered page, and because the ID still sits in Tag Manager the symptom looks like a caching fault rather than a deleted line. Use a child theme or a field the theme preserves across updates.

Whichever route you take, be clear about what it bought you: a location. Whether individual tags are allowed to fire from that container is a separate decision, made by consent defaults and trigger conditions.

Pick by site type:

- **Simple brochure site:** a dedicated GTM plugin handles it, since there's no commerce data to protect.
- **WooCommerce store with a consent banner:** use a maintained integration that can print consent defaults before the GTM snippet, or the banner loses the race on first paint.
- **Custom theme built in-house:** child theme header code, so placement is reviewable in version control.

## Setting Consent Before Tags Fire in the UK

A green tick in Preview mode tells you the container rendered. It says nothing about whether the analytics and advertising tags inside it had a lawful basis to run. UK sites get caught by treating the first as proof of the second.

Under PECR, non-essential cookies and similar storage need consent before they're stored or accessed. The [ICO's guidance on cookies and similar technologies](https://ico.org.uk/for-organisations/direct-marketing-and-privacy-and-electronic-communications/guide-to-pecr/cookies-and-similar-technologies/) sets the bar as consent that is freely given, specific, informed and based on a clear positive action, and it requires that visitors can enable or disable non-essential cookies easily. Reject has to be as findable as accept, which rules out a grey "manage preferences" link hiding the refusal path.

Google's own requirements turned this into a build step. Since **March 2024**, Consent Mode v2 has been operationally important for measurement, personalised advertising and remarketing across UK and European traffic, as [UK implementation guidance on Consent Mode v2](https://solution25.com/uk/how-to-integrate-google-analytics-4ga4-with-shopware-6/) sets out. The practical shape is a default block in the head, before the GTM container, with every signal denied and the region pinned to GB:

`gtag('consent','default',{analytics_storage:'denied',ad_storage:'denied',ad_user_data:'denied',ad_personalization:'denied',region:['GB']});`

Update those signals only after an affirmative choice, and add a consent check to every analytics and advertising tag so a granted state releases them.

### Mapping the four signals

| Consent signal | What it controls | Default before choice |
| --- | --- | --- |
| analytics_storage | Analytics cookies and measurement | denied |
| ad_storage | Advertising cookies | denied |
| ad_user_data | Sending user data to Google for advertising | denied |
| ad_personalization | Personalised ads and remarketing | denied |

> **Practical rule:** if the consent block runs after the container, you've built a tag manager that outruns the banner.

Denied consent doesn't produce silence. Google tags may send cookieless pings instead of reading or writing analytics cookies, so conversions, audiences and remarketing lists look different from a pre-consent build, and WooCommerce purchase tracking follows the same pattern. Write that gap down and report consent rates beside conversion figures, so a fall in reported revenue isn't read as a fall in sales. Experiment assignment is affected too, which is why it's worth checking the [privacy and consent setup for experimentation](https://www.otterab.com/docs/getting-started/privacy-and-consent) before trusting a variant's conversion count.

## How to Install the GTM Container Step by Step

The sequence below is the one I'd follow on a fresh site. Each step carries a reason, and each carries the mistake that usually undoes it.

![A step-by-step infographic showing how to properly install and configure a Google Tag Manager container in WordPress.](https://cdnimg.co/3716ee4f-bd1a-44a8-ac85-c2df5af21725/1ad1db03-2a87-455d-9d3a-7371192d7568/google-tag-manager-in-wordpress-installation-steps.jpg)

1. **Create a Web container and copy its ID.** In Google Tag Manager, choose Web when the container is created, then copy the `GTM-XXXXXX` value from the top bar. The slip here is picking another container type, such as a server container, which produces an ID that a browser snippet can't use.

2. **Copy both generated snippets.** GTM gives you a script for the head and a noscript block for the body. Take both. Teams often grab the head script and skip the noscript, which removes coverage for visitors with JavaScript blocked or still loading.

3. **Place the consent default block first, then the head snippet.** The consent block goes nearest the top of the head, with the GTM script immediately after it. GTM must not execute before the denied defaults exist, and the common failure is pasting the container first and the consent call somewhere lower down, which lets tags fire on load.

Here's a walkthrough if you prefer to see the placement and publishing flow on screen rather than read it:

<iframe width="100%" style="aspect-ratio: 16 / 9;" src="https://www.youtube.com/embed/kqAwfYSf9QQ" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>

4. **Put the noscript snippet directly after the opening body tag.** It belongs there and not in the footer, because moving it down the document reduces the coverage it was added to provide.

5. **Save, then purge the page cache.** Clear the cache from your caching or optimisation plugin, and from any host-level cache or CDN. A cached copy served without the snippet makes a finished install look invisible in the page source.

6. **Open Preview mode and connect it.** Enter the live site URL in GTM Preview, load the site, and confirm the debug panel attaches and lists the container. If it won't connect, stop and fix that before touching tag configuration.

Don't publish a container version until the checks in the next section pass.

## How to Check the Container Is Working

Testing is a sequence, not a glance. The version that catches real problems is the one run in a clean browser profile where nothing has been accepted yet.

![A checklist showing four steps to verify that the Google Tag Manager container is correctly installed and working.](https://cdnimg.co/3716ee4f-bd1a-44a8-ac85-c2df5af21725/938b8f29-28b1-4ccf-a2c4-e5347d1d201b/google-tag-manager-in-wordpress-container-checklist.jpg)

Clear cookies, open the site in a private window, and do nothing. Open developer tools, watch the network requests and inspect storage. Before any choice is made, there should be no analytics or advertising requests leaving the browser. Grant analytics consent only, reload, and confirm that only the approved tags fire. Then grant advertising consent and check the additional requests appear.

Run the same journey inside GTM Preview with Tag Assistant, and read the Consent tab to see the default state the container received. Finish in GA4 Realtime, where your own visit should show up within a minute or two.

### The checks worth repeating

| Check | Where to look | Expected result |
| --- | --- | --- |
| Container loads once | Page source, search for GTM- | One container ID and one head snippet |
| Consent default runs first | Tag Assistant consent view | Defaults set to denied before the GTM script runs |
| Analytics waits for consent | Network tab with no interaction | No analytics requests before consent is granted |
| GA4 receives the visit | GA4 Realtime report | Your visit appears within a minute or two |

> Trigger order is a promise the container makes to itself. It can't control a plugin that prints a pixel in the footer.

That's the trap. Tags arrive from WordPress plugins, theme files, hard-coded scripts and server-side integrations as well as from the container, and the [ICO's explanation of storage and access technologies](https://ico.org.uk/for-organisations/direct-marketing-and-privacy-and-electronic-communications/guidance-on-the-use-of-storage-and-access-technologies/what-are-storage-and-access-technologies/) is explicit that PECR applies to any script or tag accessing information on a user's device, whether or not cookies are involved. Keep a short tag inventory listing purpose, vendor, data fields, consent category, firing condition and owner, then re-run this sequence after every plugin, theme or banner update. For a fuller testing routine, this [Google Tag Manager testing walkthrough](https://www.otterab.com/blog/google-tag-manager-testing) covers the same checks in more depth.

## Fixing Common GTM WordPress Problems

Failures after a WordPress install tend to arrive in a predictable order, and most of them are caching or duplication rather than anything wrong inside GTM itself.

Preview refusing to connect is the first one, almost always because the served page doesn't contain the snippet yet. Purge the page cache, the plugin cache and any CDN cache, then reload in a private window. If Preview still won't attach, view source and search for `GTM-` before you touch a single tag setting.

Duplication is the second. An old analytics plugin that still injects its own container, or its own Google Analytics snippet, leaves you with two IDs in the source and double-counted pageviews.

| Symptom | Likely cause | Fix |
| --- | --- | --- |
| Preview will not connect | Cached page without the GTM snippet | Clear page and plugin cache, then reload in a private window |
| Two GTM IDs in page source | Old analytics plugin injects its own snippet | Deactivate the old plugin or remove the duplicate code |
| Tags fire before consent | Consent block placed after the GTM snippet or duplicated by a plugin | Put defaults first in the head and disable the extra output |
| GA4 shows no data | Wrong measurement ID or paused tag in the live version | Check the ID in the tag and publish the tested version |

The last habit worth building: after every theme or plugin update, view the rendered head and confirm your consent defaults and container snippet are still there, in that order. Updates overwrite header edits more often than anyone expects.

## Keeping GTM Fast and Accurate for Tests

Centralising tags improves governance, not speed. An unmanaged container becomes a single point of JavaScript bloat, and because it loads early on every page, everything inside it competes with the content the visitor came for. Plugin adoption shows how much weight that represents: between June 2023 and July 2024, the number of sites running the DuracellTomi Google Tag Manager for WordPress plugin rose from **9,418 to 15,640**, a **66.1% increase**, according to [TheMetix's plugin figures](https://themetix.com/plugins/duracelltomi-google-tag-manager).

### Set the baseline before adding anything

Measure real-user LCP and INP, plus page weight, with GTM disabled, then again with it enabled and with consent denied. Analytics, chat and advertising scripts are among the usual contributors to heavy JavaScript execution and poor interaction responsiveness, as [technical SEO guidance on Core Web Vitals](https://seohandbook.co.uk/technical-seo/core-web-vitals/) notes. Two numbers, taken a week apart on the same template, tell you more than any synthetic score.

### Trim in this order

- **Remove duplicate snippets first.** Old plugin output and hard-coded analytics are the cheapest win and the least risky.
- **Limit triggers to the pages that need them.** A purchase tag belongs on the order-received URL, not sitewide.
- **Delay non-critical marketing tags** where it's lawful and commercially sensible, then confirm the delay doesn't drop consent-gated events.
- **Review the container quarterly.** Tags outlive the campaigns that justified them.

Experiments add a layer. Consent checks, caching, optimisation plugins and competing personalisation scripts can change when a variant appears or whether a visitor is included at all, so re-check traffic allocation after every tag change. Compare variants only within the same consent path, otherwise your conversion counts are measuring two different populations. Our [Google Tag Manager best practices](https://www.otterab.com/blog/google-tag-manager-best-practices) guide goes further into sequencing and trigger hygiene.

## Confirm the Setup Before Adding More Tags

There's a gate here, and it's simple: no new tags and no new container version until the install, consent and verification checks all pass. Adding a fifth tag to a setup with unresolved consent problems just gives you more places to hunt later.

Three things confirm the gate has closed. First, the tag inventory exists as a written document, with purpose, vendor, data fields, consent category, firing condition and owner for each entry. Second, the banner has been tested three ways, accept, reject and no choice, and the reject path works. Third, someone on the team owns the re-test that follows each plugin, theme or banner update.

Then move forward. Create the first GA4 configuration tag inside the container, attach it to a named conversion event the team will report on, and watch that event land in GA4 Realtime. If you'd rather learn the QA habit from a worked example, this [server-side tagging QA walkthrough](https://www.cometogether.media/blog/single-post/google-tag-manager-conversion-tracking) from Come Together Media shows how the same discipline applies once part of the stack moves server-side. Otter A/B connects to a GA4 property with one click via OAuth, and any existing GA4 event can serve as a test goal without extra tracking code, which keeps experimentation off the tag pile you just cleaned up.

> A container that loads is only the start. The setup is finished when consent, verification and documentation agree.

---

The container you've just verified is the right place to start measuring outcomes rather than clicks. Otter A/B installs on WordPress in under two minutes, reads the purchase and revenue events your GA4 setup already sends, and reports which variant earned more instead of which one got more taps. Run your first test against a container you trust by starting free at [Otter A/B](https://www.otterab.com).

---

Canonical page: https://www.otterab.com/blog/google-tag-manager-in-wordpress
