Loading tutorials…
Loading tutorials…
Most WordPress GTM installs are wrong in subtle ways — snippet in the wrong position, missing <noscript> tag, or hardcoded into a theme that updates monthly. This walks through the install that actually survives.
Who this is forWordPress site owners installing GTM for the first time, or fixing a partial install. Especially relevant if you plan to run multiple tags (GA4, Meta Pixel, LinkedIn Insight, conversion tags) — GTM is the layer that holds them.
What you'll need
Step 1
Three paths: GTM4WP plugin (recommended), functions.php injection (developer-friendly), theme header.php (worst — survives until theme update).
Path A — GTM4WP plugin by Thomas Geiger: most reliable. Free, well-maintained, handles snippet placement correctly, survives theme updates. Used on 500k+ sites.
Path B — functions.php with wp_head/wp_body_open hooks: clean for developers. Survives theme updates only if functions.php is in a child theme. Lost if you switch themes.
Path C — theme header.php direct paste: worst path. Lost on every theme update. Many themes load header.php via blocks (FSE), making the paste impossible without theme override files.
Recommendation: GTM4WP for almost every site. Use functions.php only if you have a developer maintaining a child theme. Avoid Path C.
Step 2
WordPress Admin → Plugins → Add New → search "GTM4WP" → Install Now → Activate. Paste GTM Container ID. Verify placement.
WordPress Admin → Plugins → Add New. Search "GTM4WP" by Thomas Geiger. Verify author before installing (look-alike plugins exist).
Click Install Now → Activate.
Settings → Google Tag Manager.
Paste your GTM Container ID (GTM-XXXXXXX) in the "Google Tag Manager ID" field.
Container code on/off → set to "Codeless injection (recommended)." This option places both the <script> in <head> and the <noscript> after <body> open, automatically.
Save Changes. The plugin handles everything else — no theme edits required.
Step 3
Add wp_head and wp_body_open hooks in your child theme functions.php. Both snippets must be present and in the right positions.
Create a child theme if you do not have one. Appearance → Themes → if no child theme exists, create one (or use a plugin like Child Theme Configurator).
Edit child theme functions.php. Add the GTM head snippet via add_action("wp_head", ...). Paste the GTM <script> exactly as Google provides, replacing GTM-XXXXXXX with your ID.
Add the GTM noscript snippet via add_action("wp_body_open", ...). Paste the <noscript><iframe...> exactly. Note: wp_body_open requires WordPress 5.2+ and theme support — most modern themes support it.
Save. Visit your homepage in a private window. View Source.
Confirm: GTM <script> appears in <head>. GTM <noscript> appears immediately after <body> open. Both contain your correct Container ID.
Step 4
Install Google Tag Assistant Chrome extension. Visit your site with Tag Assistant enabled — GTM container should be detected with no errors.
Install Google Tag Assistant Legacy or the newer Tag Assistant Companion from the Chrome Web Store.
Visit your homepage in a regular tab (not private window — Tag Assistant needs the extension permissions).
Click the Tag Assistant icon. It should detect Google Tag Manager with your Container ID.
Green tag icon = working. Yellow = non-critical warning. Red = error.
Common warning: 'Tag Manager loaded asynchronously, may miss early events.' This is normal for codeless injection — no action needed.
Step 5
tagmanager.google.com → Preview. Enter your site URL. A new debug tab opens. Use this to test every new tag before publishing.
Open tagmanager.google.com → your container → click "Preview" (top right).
A new tab opens showing the Tag Assistant pane. Enter your site URL in the field and click Connect.
Your site opens in a debug-mode tab with a bottom-bar overlay. The Tag Assistant pane shows every event the GTM container fires in real time.
Click through your site. Every page load, click, form submit fires events in the debug stream. You see which tags fire, which trigger fires them, and what variables passed.
This is your test environment. Always Preview before clicking Submit/Publish in GTM — published changes go live immediately to all real visitors.
Step 6
Inside GTM, add a "Google Tag" (GA4) configured for your Measurement ID, firing on All Pages. Test in Preview. Submit and publish.
GTM → Tags → New.
Tag Configuration → Google Tag.
Tag ID → paste your GA4 Measurement ID (G-XXXXXXXXXX). For Google Ads conversion tags, use "Google Ads Conversion Tracking" template — needs Conversion ID + Conversion Label.
Trigger → All Pages.
Save. Click Preview to test (if not still in Preview mode).
Verify the tag fires in the Preview debug pane.
Click Submit → name the version "Initial GA4 install" → Publish.
Step 7
If your audience includes EU users, your GTM tags must respect cookie consent. Use Consent Mode v2 or a built-in CMP variable.
Install a CMP plugin (Cookiebot, CookieYes, Complianz). All three integrate with GTM via a "Cookie Consent" data layer variable.
In GTM → Variables → New → Data Layer Variable → name "ConsentMarketing." Variable value: read from the data layer event the CMP publishes.
On every marketing tag (GA4, Meta Pixel, LinkedIn Insight), add a blocking trigger: Tag fires UNLESS ConsentMarketing != "granted."
Configure Consent Mode v2 for GA4 specifically: GA4 → Admin → Data Streams → Configure tag settings → Consent settings. Set ad_user_data and ad_personalization to require consent.
Test in Preview: load the page WITHOUT clicking the consent banner. Marketing tags should NOT fire. Click consent banner Accept → tags fire on next page load.
Common mistakes
Pasting only the <script> snippet, not the <noscript> snippet
What goes wrong: GTM snippet is two parts: <script> in <head> and <noscript> after <body> open. Missing the <noscript> means JS-disabled visitors (3-5% of traffic, plus some bots) never trigger GTM. Reporting under-represents non-JS visits.
How to avoid: Use GTM4WP codeless injection — handles both automatically. Or for functions.php, use both wp_head and wp_body_open hooks.
Putting the GTM snippet in the body, not the head
What goes wrong: Some 'easy' guides say paste the snippet in any footer.php. Snippet placement matters — GTM in <head> loads earliest and catches initial pageview reliably. In <body>, you miss the first 100-300ms of tracking and async tags may not fire at all.
How to avoid: GTM <script> goes in <head> via wp_head hook. <noscript> goes after <body> open via wp_body_open. Never in <body> arbitrary position.
Installing GTM via theme header.php without a child theme
What goes wrong: Theme update overwrites header.php. GTM disappears. Every downstream tag (GA4, Pixel) goes dark. Typical detection lag: 1-4 weeks. All data in the window is lost.
How to avoid: Use GTM4WP plugin. Or use a child theme so functions.php and header.php survive parent theme updates.
Multiple GTM containers installed at once
What goes wrong: Common when migrating between agencies — old container snippet was never removed, new one added. Every tag now fires twice (one from each container). Conversion data doubles. CPA reports lie.
How to avoid: View Source on your homepage. Search 'GTM-'. You should see your Container ID ONCE in the <script> and ONCE in the <noscript>. If multiple Container IDs appear, find and remove the old one.
Publishing GTM container without Previewing first
What goes wrong: A broken tag goes live and breaks tracking for everyone immediately. Without Preview testing, you have no way to verify before deployment.
How to avoid: Always Preview every change. Click through your site in Preview mode. Verify every tag fires only when expected. THEN Submit and Publish.
Not respecting GDPR/cookie consent in tag triggers
What goes wrong: EU visitors fire marketing tags before consenting. GDPR violation risk. Fines can be 4% of global revenue. Even smaller fines (€50k-200k) wipe out a small business.
How to avoid: Use Consent Mode v2 for Google tags. For non-Google tags (Meta, LinkedIn), add a consent-gated blocking trigger to every marketing tag. Test in Preview without consent acceptance — tags must not fire.
Recap
Done — what's next
How to install Google Analytics 4 on WordPress (3 valid paths)
Read the next tutorial
Hand it off
GTM is the layer that makes every other tag work right. Get it wrong and GA4/Pixel/LinkedIn all go sideways. A vetted analytics specialist installs GTM + a baseline tag library (GA4, conversion tags, consent gating) in 90 minutes — typically $60-120 at $14-16/hr.
See specialist rates
GTM4WP for almost everyone — survives theme updates, no code maintenance, free, well-maintained. functions.php only if you have a developer maintaining a child theme AND want stricter control over snippet placement (rare).
Technically yes but never recommended. You will double-count pageviews. Pick GTM (preferred — more flexible) and remove the direct gtag.js. Or use direct gtag.js for the simplest case and skip GTM.
Top 3 causes: (1) container is in Preview mode but tags configured for Live workspace — open Preview tab in GTM, click Continue; (2) the GTM <script> snippet was injected after a <script> that errors and halts JS execution — check browser console; (3) caching plugin serves a stale page without the GTM snippet — purge cache.
Minimally when configured correctly (async loading, <50ms parser block). GTM-loaded tags load on demand after page render, so they do not block initial paint. Performance impact comes from heavy tags loaded INSIDE GTM, not GTM itself.
Site Kit can install the GTM snippet, but it offers fewer GTM-specific features than GTM4WP. Use Site Kit if you want a unified Google products dashboard inside WordPress. Use GTM4WP if you want the cleanest, most maintainable GTM-only install.
Check three places: (1) Plugins → look for old GTM plugin, deactivate and delete; (2) Appearance → Theme File Editor → header.php → search for 'GTM-' and remove; (3) Settings → Code Snippets or WPCode → look for GTM snippets and disable. View Source after each to confirm.
WordPress
There are three valid ways to install GA4 on WordPress, and the "easy" one is usually the wrong one. This walks through GTM (preferred), MonsterInsights (plugin-driven), and direct gtag.js — and how to tell which fits your stack.
WordPress
Meta Pixel install on WordPress is easy in one sense and treacherous in another — there are three valid paths and they don't play well together. This is the decision framework + the install + the verification that 60% of DIYers skip.
WordPress
Your forms convert — but only if your analytics know. Every WordPress form has its own quirks for firing tracking events. This walks through Gravity Forms, WPForms, and Contact Form 7 with the GA4, Meta Pixel, and Google Ads tracking that turns submissions into measurable conversions.
WordPress
WordPress is the easiest CMS to start with and the easiest to make a mess of by month 18. This is the honest framework for when DIY becomes the bottleneck and a specialist pays for themselves.