How to Add Google Tag Manager to WordPress
Add, test, and manage Google Tag Manager on your WordPress site.
What Google Tag Manager Does
To add Google Tag Manager to WordPress, create a container, copy its two code snippets, and place them on your site. Then test the setup in preview mode before you publish the container. This keeps your tracking tools in one place.
Google Tag Manager, often called GTM, is a free tool for adding and managing tracking tags. A tag is a small piece of code that sends data to a service, such as Google Analytics. The GTM container loads on your WordPress pages. You can then set rules for when each tag should run.
GTM does not collect useful data by itself. You must add and set up the tags you need. For example, an Analytics tag can track page views, while another tag can record form submissions. A careful setup helps you avoid duplicate or unwanted data.

Why Use GTM With WordPress?
GTM gives you one place to manage many tracking tags. You can add or change a tag without editing your theme each time. This can save time when marketing or analytics needs change.
It also supports triggers, which decide when a tag runs. A trigger can fire on every page, or only after a visitor clicks a chosen link. Variables can pass details, such as the page URL, into a tag. These tools let you track actions that matter to your site.
GTM can make tag changes safer when you use its preview and version features. Test a change before publishing, then keep a record of each live version. GTM does not make every site faster by default. Too many tags can slow pages, so keep only the tags you need.
- Manage tags from one shared container
- Test changes before they go live
- Set rules for when tags run
- Keep a history of published versions

Install Google Tag Manager on WordPress
First, sign in to Google Tag Manager and create an account. Add a web container for your site, then note its container ID. It begins with GTM- and appears in the container workspace. Do not confuse this ID with an Analytics measurement ID.
Open the container’s installation instructions and copy both code snippets. One belongs in the page head. The other belongs just after the opening body tag. Google explains the placement in its Google Tag Manager installation instructions.
Choose one method to add the snippets. A plugin made for header and body code is often the easiest option. A theme may also offer fields for custom scripts. If you edit theme files, use a child theme or a safe code-injection tool. A theme update can remove changes made to the parent theme.
- Back up your site. Save a current copy before changing its code or settings.
- Pick one install method. Use a plugin, theme setting, or child theme. Do not add the same container through several methods.
- Place the head snippet. Paste the first snippet inside the page head, as close to its opening tag as your tool allows.
- Place the body snippet. Paste the second snippet right after the opening body tag, if your chosen method supports that location.
- Save and clear caches. Save the change, then clear your WordPress, hosting, and browser caches.
Some WordPress plugins add the snippets for you after you enter the container ID. Check the plugin’s instructions and confirm both code parts are placed. If it adds only one snippet, use a method that supports the missing part. Avoid installing two plugins that both add the same container.

Check That GTM Works and Fix Common Errors
In Tag Manager, select Preview and enter your site address. The preview tool opens your site and reports whether it can connect to the container. Visit a few pages, then check that the container loads on each one. This confirms the base code is present, but not that every tag works.
Next, test each tag and trigger you plan to use. For an Analytics tag, check that it fires once on the pages you expect. A tag that never fires may have a wrong trigger or a missing container snippet. A tag that fires twice may be installed both through GTM and another plugin.
If preview cannot connect, check the container ID and snippet locations first. Then pause any cache or script-minifying tool and test again. These tools can change when scripts load. Restore each setting one at a time after the test.
Also check for consent settings or security tools that block scripts. Test while signed out of WordPress, since some plugins change behavior for site admins. If the container works on one page but not another, compare the page templates and any custom header settings. Fix the source rather than adding another copy of the code.
- No container found: Check the ID, both snippets, and cached page output.
- Tag does not fire: Review its trigger and any consent or blocking rules.
- Tag fires twice: Search for duplicate plugin, theme, or hard-coded installs.
- Preview fails: Check browser extensions, cache tools, and script blockers.

Manage Tags With Care
Give tags, triggers, and variables clear names. For example, “Analytics – all pages” is easier to review than “Tag 3.” Add a short note when you create or change a tag. A teammate should be able to tell what it tracks and why it exists.
Use folders to group tags by purpose, such as analytics or ads. Keep a simple record of which service owns each tag and who asked for it. Before publishing, use preview mode to check the tag on key pages. Test forms and checkout steps where relevant.
Publish related changes together, and describe each new version. If a new tag breaks tracking, the version history helps you restore the last working setup. Review the container every few months. Remove tags you no longer use, and check that each remaining tag still has a clear purpose.
Keep privacy in mind when you choose what to track. Do not send personal details through tags unless you have a valid reason and the right safeguards. Set consent behavior to match your site’s needs and rules. A tidy container is easier to test, safer to change, and simpler to hand over.
Next Steps for Your WordPress Setup
To add Google Tag Manager code in WordPress, place its two snippets in the right parts of your pages, then test the container. Use one install method and check for duplicate code. After that, add only the tags your site needs.
Start with a basic tag and confirm it fires as planned. Then add more tracking in small steps, testing each change before you publish. This approach makes errors easier to spot and keeps your WordPress tracking setup clear.
Step-by-step
- 01 Create a web container
Set up a Google Tag Manager account and create a web container for your WordPress site. Note its GTM container ID.
- 02 Copy both code snippets
Open the container installation instructions and copy the head and body snippets. Keep their intended placements in mind.
- 03 Add the snippets to WordPress
Use one plugin, theme setting, or child theme method. Place each snippet in the correct part of the page.
- 04 Test the container
Clear site caches, open Preview mode, and connect it to your site. Check that the container loads and tags fire as expected.
Frequently asked questions
- How do I add Google Tag Manager to WordPress?
- Create a web container, copy its two snippets, and add them to your WordPress site. Test the container in preview mode before publishing tags.
- Can I install Google Tag Manager with a WordPress plugin?
- Yes. A plugin can add the container code or its ID for you. Check that it places both snippets, and do not use another method to add the same container.
- How can I check if Google Tag Manager works on WordPress?
- Use Preview in Tag Manager and connect it to your site. Confirm the container loads across pages, then check that each tag fires only when its trigger should.
- Why is my Google Tag Manager tag not firing?
- Check the tag’s trigger, container ID, and code placement. Caches, consent settings, or script blockers can also stop a tag from firing.
- Should I add Google Tag Manager code to my WordPress theme?
- You can add it through a child theme, but theme updates may remove edits to parent theme files. A plugin or theme setting can be easier to maintain.
Related reading
How to Check Views on WordPress and Grow Your Blog
Track WordPress views, read traffic trends, and bring more readers to your blog.
How Do I Change a Meta Description in WordPress?
Set better WordPress descriptions for search results and social shares.
How Do You Indent Text in WordPress?
Indent paragraphs in WordPress with blocks, HTML, or a small CSS rule.