Loading tutorials…
Loading tutorials…
There are three legitimate ways to install GTM on a WordPress site. Each suits a different operator. Pick wrong and you'll either have a brittle install, no dataLayer, or a developer dependency you didn't want.
Who this is forWordPress site owners (self-hosted, not WordPress.com Free) who need GTM to manage analytics and ad pixels. If you're on WordPress.com Free, you can't inject scripts and need to upgrade or move to self-hosted first.
What you'll need
Step 1
Path A: a header plugin (simplest, no dataLayer). Path B: direct theme edit (full control, dev-required). Path C: GTM4WP (best for WooCommerce + dataLayer out of the box).
Path A — Header Footer Code Manager (or similar plugin). Pros: 5-minute install, no code. Cons: no dataLayer enrichment, breaks if the plugin is deactivated, adds a plugin dependency.
Path B — Edit header.php directly via Appearance → Theme File Editor. Pros: zero plugin dependency, full control. Cons: lost on theme update unless using a child theme, requires PHP comfort.
Path C — GTM4WP (the dedicated plugin by Thomas Geiger). Pros: deep WooCommerce integration, automatic dataLayer pushes for purchases, scroll tracking, video events. Cons: more configuration up front, opinionated about how it pushes data.
Recommendation by site type: brochure site → Path A. Custom-built theme with strict performance needs → Path B with a child theme. WooCommerce store → Path C (this is the only path that doesn't require you to hand-code WooCommerce dataLayer pushes).
Step 2
Install "Header Footer Code Manager" (or "Insert Headers and Footers" by WPBeginner). Paste GTM snippets into the corresponding boxes.
Plugins → Add New → search "Header Footer Code Manager" → Install → Activate.
In the plugin settings (Settings → Header Footer Code Manager), click Add New Snippet.
Name: "GTM Head." Location: "Site Wide Header." Display: "Show on all devices." Paste the GTM <script> snippet (the head one).
Repeat: Add New Snippet → "GTM Body." Location: "Site Wide Body Open." Paste the <noscript> <iframe> snippet.
Save both. Open the live site in incognito → View Source → search for GTM-XXXXXXX → confirm both snippets are present.
Step 3
Open Appearance → Theme File Editor → header.php. Paste both snippets in the right spots. Use a child theme so updates don't overwrite.
First, set up a child theme if you don't have one already. Without one, the next theme update will wipe your install.
Appearance → Theme File Editor → select your child theme → header.php.
Find the <head> tag. Paste the GTM <script> snippet immediately after <head>, before any other <script> or <link>.
Find the opening <body> tag (usually further down, sometimes with class names). Paste the <noscript> <iframe> snippet immediately after.
Update File. View source on the live site to confirm both snippets are present and properly placed.
Step 4
GTM4WP is the dedicated GTM plugin for WordPress. Configure it once, get dataLayer pushes for free.
Plugins → Add New → search "GTM4WP" → Install → Activate.
Settings → Google Tag Manager → enter your Container ID (GTM-XXXXXXX).
Set "Container code on/off" to ON. Set "Container code placement" to "Codeless injection" (preferred) or "Off — manual coding."
Under Integration → WooCommerce, enable ecommerce data and pick the data model: 'enhanced ecommerce v2 (gtag, GA4)' for most modern stacks.
Save. Open the live site in incognito → DevTools console → type window.dataLayer → confirm the array is populated with page and ecommerce data.
Step 5
Use Tag Assistant (tagassistant.google.com) to confirm GTM is firing on every page type: home, post, page, and (if WooCommerce) product, cart, checkout.
tagassistant.google.com → Add Domain → enter your WordPress URL.
Click Connect. A new tab opens in debug mode.
Navigate: home → a blog post → a static page → a WooCommerce product → cart → checkout.
Watch the Summary tab. GTM should fire on every page. The Container Loaded event should appear at each step.
If GTM4WP, also verify the dataLayer in the Variables tab: you should see ecommerce.detail (product view), ecommerce.add (cart), ecommerce.checkout (checkout step).
If anything is missing, re-check the install path. The plugin path is the easiest to debug; the theme-edit path is the easiest to break with future theme updates.
Step 6
Write down which path you used, where the GTM Container ID is configured, and what to do if WordPress or the theme updates.
In a WordPress admin note (Tools → Notes plugin, or simply a Page set to private), document: install path used, plugin name if applicable, theme name + version if direct edit.
If using a child theme: note the parent theme version. After every parent theme update, verify the child theme still applies.
If GTM4WP: note the e-commerce data model setting (Universal vs GA4 vs Enhanced v2) so the next operator doesn't accidentally change it.
Add the GTM Container ID to your password manager under 'WordPress / Google Tag Manager.' Future you will need it.
Common mistakes
Editing the parent theme instead of a child theme
What goes wrong: Theme updates wipe your GTM install. You discover this 6 months later when a routine update strips analytics from the site. Weeks of data lost.
How to avoid: Always use a child theme for direct edits. WPBeginner has a 10-minute child theme setup guide if you don't have one.
Running both GTM4WP and a header plugin
What goes wrong: GTM fires twice on every page. Conversions are double-counted. GA4 sessions look 2x reality. Ad platforms over-attribute. Months of corrupted data.
How to avoid: Audit Plugins. If GTM4WP is installed, remove all other GTM-injecting plugins. View source and confirm only one GTM-XXXXXXX appears.
Picking the plugin path for a WooCommerce store
What goes wrong: You spend 2 days hand-coding dataLayer pushes for purchase, add-to-cart, and checkout events. Each one breaks on the next WooCommerce update.
How to avoid: Use GTM4WP for any WooCommerce site. The plugin maintains the dataLayer pushes through WooCommerce updates so you don't have to.
Pasting the body snippet inside <head>
What goes wrong: The <noscript> <iframe> doesn't render where it should. JavaScript-disabled users (some bots, accessibility tools) aren't tracked. Minor data loss but it pollutes audit logs.
How to avoid: Always paste the head snippet inside <head> and the body snippet immediately after the opening <body> tag. Two different locations.
Forgetting to publish the GTM workspace
What goes wrong: You install GTM perfectly. You add tags inside the GTM container. You hit Save on every tag. Nothing fires on the live site because Publish was never clicked.
How to avoid: After every change inside GTM, click Submit → Publish at the top-right. Save is local; Publish makes the change live.
Recap
Done — what's next
How to fire GA4 through Google Tag Manager — without double-counting
Read the next tutorial
Hand it off
Picking the right install path on WordPress matters more than the install itself — switching paths later is a half-day of unwinding. A GTM specialist will pick the right path for your stack, install GTM + dataLayer + e-commerce events, and document for handoff. Typically $150-300 one-time at $14-16/hr.
See specialist rates
Only on Business plan or higher. Free, Personal, and Premium plans block script injection. If you're on those tiers, you'd need to upgrade to Business or migrate to self-hosted WordPress.org first.
Yes. GTM4WP injects at the WordPress core level, so it runs regardless of which builder rendered the page. The dataLayer pushes for WooCommerce events also fire correctly through page builders that use WooCommerce widgets.
Usually no, because GTM is a head/body script and caching plugins respect those. The risk is with aggressive optimization plugins (Autoptimize, Perfmatters) that try to combine or defer scripts. Exclude GTM from any 'combine JS' or 'defer JS' settings.
Use only one. Site Kit installs GA4 directly via gtag — if you ALSO inject GA4 via GTM, you'll double-fire. Pick: Site Kit OR GTM-managed GA4. For most stacks needing pixels beyond GA4, GTM wins.
Move the install to a child theme. The child theme persists through parent theme updates. If you used a header plugin instead of theme edit, this won't happen — but the plugin adds a dependency.
Google Tag Manager
Firing GA4 through GTM is the foundation of every modern analytics stack. Done right, it's one tag and a clean event map. Done wrong, you double-count every event and pollute six months of reports. This is the right way.
Google Tag Manager
Meta doesn't ship a native GTM tag template, so the install is a Custom HTML tag. Done right, this is cleaner than the official Meta pixel-injection method — done wrong, you double-fire every event and the Events Manager fills with junk.
Google Tag Manager
The default Form Submission trigger handles 70% of forms. The other 30% (AJAX forms, React forms, Webflow forms) need a custom pattern. This walks through both, and which one you need.
Google Tag Manager
DIY GTM works fine for simple stacks. It starts breaking down when you need GA4 + Meta + TikTok + Google Ads all firing accurately with deduplication. Here's the honest framework for when to hire.