Skip to content

How to Install Google Tag Manager in WordPress: 4 Methods

Flat site to tag flow icon beside the title How to Install Google Tag Manager in WordPress

To install Google Tag Manager in WordPress, create a web container in Tag Manager. Then add its two code blocks with a plugin or a small snippet. The whole job takes about 15 minutes.

I tested three install methods on WordPress 7.1.3 with the Twenty Twenty-Five theme in October 2026. I used the sample container ID from Google’s own install guide, and I read the page source after each method.

This guide shows the account and container steps. Then it covers the GTM4WP plugin, the WPCode plugin and a manual method. A short last method covers Site Kit by Google. You also get the real script positions I measured, a way to check the install and fixes for the common problems.

What Is Google Tag Manager?

Google Tag Manager, or GTM, is a free tool that lets you add and change tracking tags without editing code each time. You install one container snippet on WordPress. Then you manage Google Analytics, ad pixels and other tags from the Tag Manager screen.

A tag is a small piece of code that sends data to another service. A trigger tells the tag when to run, such as on every page view or on a button click. A variable holds a value the tag needs, such as a page URL.

GTM is not an analytics tool. It does not report anything itself, and it only delivers the tags that do. If you only need Google Analytics, our guide on how to add Google Analytics on WordPress covers a simpler route.

Do You Need Google Tag Manager on WordPress?

You need Google Tag Manager when you run more than one or two tags, or when you want to change tracking without touching theme files. A store with Google Analytics, a Meta pixel and conversion tags gains the most. A small blog with only Analytics can skip it.

GTM helps in three situations. Marketers can add tags without waiting for a developer. Tag changes are versioned so you can roll back, and one snippet replaces a pile of scripts in your header.

It also adds a layer to debug. If something breaks, you now have a site, a plugin and a GTM container to check. Keep your setup simple, and add tags only when you have a use for the data.

For store reports, a dedicated plugin can be easier than GTM. See our list of WooCommerce customer analytics plugins before you build custom tags.

What You Need Before You Install GTM

Before you start, gather three things: a Google account, admin access to WordPress and a recent backup. You also need a theme that calls wp_body_open, which places the second GTM block. Most current themes do, and Twenty Twenty-Five printed it in my test.

WordPress core added the wp_body_open hook so themes and plugins can print code right after the opening body tag. If an older theme lacks it, GTM4WP offers a footer placement that works with any theme.

Check your theme first. Open your site’s source and search for the text <body. If the line after it holds nothing special, you can still add the hook yourself or choose the footer placement.

Do not install GTM through two methods at once. In my test, adding GTM4WP on top of a manual snippet printed two gtm.js loaders and two noscript blocks on the same page. Every tag could then fire twice and inflate your numbers.

How to Install Google Tag Manager in WordPress

You can install Google Tag Manager in WordPress in two parts. First, create the account and container in Tag Manager and copy the container ID. Then add the container code with the GTM4WP plugin, the WPCode plugin or a manual snippet.

Four steps to install Google Tag Manager in WordPress

Step 1: Create a Tag Manager Account and Container

Create the account at tagmanager.google.com with your Google account. Google’s setup guide lists the steps, and they are the same for every site.

Follow these steps:

  1. Open the Accounts tab: Sign in, click the Accounts tab at the top left and choose Create Account.
  2. Fill in Account Setup: Enter an account name and pick your country.
  3. Name the container: Use your top-level site address, such as www.example.com. Google says you do not need a container for each page.
  4. Choose Web: Select Web as the container type, click Create and accept the Terms of Service.
    Google Tag Manager Add a New Account form with the container name and Web platform

After you accept, Tag Manager shows the install code. Copy the container ID, which starts with GTM, such as GTM-ABCDEFGH.

You need only that ID for the plugin methods. For the manual method you also need both code blocks.

Step 2: Add the Container Code to WordPress

Google’s install guide says to paste the first block “as high in the <head> tag as possible”. The second block goes immediately after the opening body tag. Each method below does both, with one difference in where the first block lands.

Pick one method and use only that one. The table shows how they compare on my test site. Any of them gives you a working Google Tag Manager WordPress setup.

MethodSetupBest forNeeds wp_body_open
GTM4WP pluginContainer ID onlyMost sitesOptional
WPCode header and body boxesPaste both blocksPasting Google’s code as isYes
Manual code snippetHooks in a child themeDevelopersYes

Method 1: Add Google Tag Manager to WordPress With the GTM4WP Plugin

GTM4WP is the plugin most WordPress sites use for GTM. GTM4WP is at version 2.0.5 as of October 2026, with more than 700,000 active installs and a 4.5 rating from 155 reviews. Its settings screen asks for the container ID and the placement of the second block.

Follow these steps:

  1. Install the plugin: Go to Plugins > Add Plugin and search for GTM4WP. Install and activate it.
  2. Open the settings: Go to Settings, Google Tag Manager. A notice asks you to enter your GTM ID until you do.
  3. Add your container: Click Add row and type your container ID in the first field.
  4. Choose the placement: Pick Automatically after the opening body tag, since your theme supports wp_body_open.
    Install Google Tag Manager in WordPress with the GTM4WP container settings
  5. Save changes: Click Save changes at the top of the screen.

The placement list has four choices: Footer of the page, Manually coded after the opening body tag, Automatically after the opening body tag, and Off. The Footer option works with any theme and needs no wp_body_open support.

After saving, my page source held the noscript block directly after the opening body tag. It also held one gtm.js loader, with the container ID I entered. With no container ID, the plugin printed only a data layer setup script and no loader.

Method 2: Use the WPCode Plugin for a WordPress Google Tag Manager Setup

WPCode lets you paste Google’s two code blocks into labeled boxes. WPCode is at version 2.3.9, with more than 3 million installs and a 4.9 rating from 1,900 reviews, as of October 2026. It suits you if you want Google’s exact code on the page.

Follow these steps:

  1. Install WPCode: Go to Plugins, Add Plugin, search for WPCode and activate it.
  2. Open the header and footer screen: Go to Code Snippets > Header & Footer.
  3. Paste the first block: Put Google’s head snippet in the Header box.
  4. Paste the second block: Put the noscript snippet in the Body box.
    WPCode header and body boxes with the Google Tag Manager code
  5. Save: Click Save Changes at the top.

The screen labels the Header box “printed in the head section” and the Body box “printed just below the opening body tag”. Both matched what I saw in the source.

One caution applies. WPCode printed the header block late in the head on my test site as the position table below shows. Google asks for the block as high as possible. A manual hook gives the best placement.

Method 3: Add the Code Manually

A manual snippet gives you full control and no extra plugin. Add two hooks: one on wp_head for the container script and one on wp_body_open for the noscript block. Put the code in a child theme or a code snippets plugin, never in a parent theme file that updates will overwrite.

Add this code and replace GTM-XXXXXXX with your container ID:

add_action( 'wp_head', function () { ?>
<!-- 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 }, 1 );

add_action( 'wp_body_open', function () { ?>
<!-- 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 } );

The number 1 after the first hook sets an early priority. The script prints near the top of the head. Our guide on how to create a WordPress child theme shows the safe place for it. If a typo causes a fatal error, see how to fix a plugin that triggered a fatal error.

Method 4: Connect Tag Manager With Site Kit by Google

Site Kit by Google is Google’s own plugin for WordPress. It can connect Tag Manager and place the container code for you. You sign in with Google and pick an account and container. Site Kit then prints the snippet. It suits sites that already use Site Kit for Analytics or Search Console.

Site Kit is at version 1.189.0 as of October 2026, with more than 5 million active installs and a 4.2 rating from 1,012 reviews. The steps below follow Google’s Site Kit Tag Manager guide.

Follow these steps:

  1. Install Site Kit: Go to Plugins > Add Plugin and search for Site Kit by Google. Install it and finish its setup with your Google account.
  2. Open the services: Go to Site Kit > Settings > Connect More Services and click Set up Tag Manager.
  3. Pick the container: Choose your account and your Web container from the dropdowns. You can also choose Set up a new container.
  4. Let Site Kit place the code: Keep the Let Site Kit place code on your site toggle on.
  5. Finish: Click Complete setup.

Site Kit shows the notice Tag Manager container already placed when it finds another container on the site. Remove the other method first so your tags do not fire twice.

Google’s guide also suggests connecting Analytics in Site Kit itself. A GA4 tag inside the container misses the custom dimensions that Site Kit adds.

Which Install Method Is Best?

The best method depends on how much control you want over where the container script prints. GTM4WP is the easiest and adds data layer features. WPCode suits pasting Google’s code as is, and a manual hook prints the script highest in the head, as Google asks.

I measured where the main container script landed in the page source on my test site. The position is a character count from the start of the page source.

Google Tag Manager script position by install method in WordPress

The manual hook put the script at character 471 of a 49,402 character head, ahead of the title tag. GTM4WP put it at character 47,071 of 50,042. WPCode’s header box put it at 46,463 of 49,407.

That does not mean the plugins are wrong. The tag still loads with async because the snippet sets j.async=true. It does not block the page. Still, for the earliest start, a priority 1 hook is the tightest option.

How to Verify That GTM Works on Your Site

Check the install in two ways: look for the container in the page source and then use Tag Manager’s Preview mode. The source check proves the code is on the page. Preview mode proves the container loads and your tags fire as planned.

Follow these steps:

  1. View the page source: Press Ctrl+U (Cmd+Option+U on a Mac) and search for gtm.js?id=. You should find one match.
  2. Count the noscript blocks: Search for ns.html?id=. One match means a single install.
  3. Open Preview: In Tag Manager, click Preview at the top right to launch Google Tag Assistant.
  4. Connect your site: Enter your website address and click Connect, as Google’s verify steps describe.

Two matches for either search point to a double install. Remove one method before you go on.

If Tag Assistant cannot connect, publish the container first. Google’s help notes that a container must be published before some connections work.

Add Your First Tag: Google Analytics 4

The most common first tag is the Google tag for Google Analytics 4. In Tag Manager, you create a tag, choose the tag type, paste your Tag ID and set a trigger. Google’s GA4 setup guide lists the exact labels.

Follow these steps:

  1. Create the tag: In your container, go to Tags and click New.
  2. Name and choose the type: Replace Untitled Tag with a name such as Google tag and choose Google Tag as the tag type. Google’s guide describes the same step.
  3. Enter the Tag ID: Paste your Tag ID in the Tag ID field.
  4. Set the trigger: Under Triggering, pick the Initialization trigger named All Initialization Events.
  5. Save, preview and publish: Click Save and test with Preview. Then click Submit and choose Publish and Create Version.

Tracking only starts after you publish. Until then the container holds a draft that visitors never see.

Does Google Tag Manager Slow Down WordPress?

GTM loads asynchronously. The container script itself does not block your page. The cost comes from the tags inside it because every tag adds scripts, requests and sometimes layout changes. A container with two tags is light, and one with fifteen is not.

Keep the tag list short and remove tags you no longer read. Test your speed before and after a new tag.

Load order matters as well. Tags that fire on every page cost more than tags that fire on one form or one button.

Use a specific trigger wherever you can, and avoid “All Pages” for tags that only matter on a few screens. Our guide on how to fix slow website loading shows what to measure, and a cache plugin can help with the rest of the page.

Also check privacy rules. If your tags set cookies, you may need a consent banner first, and our guide on GDPR for WooCommerce covers the basics.

Sites that handle patient data need stricter rules for tags, which are set out in HIPAA rules for tracking pixels and analytics.

Common Google Tag Manager Problems on WordPress

Most problems come from a double install, a cache that serves an old page or a theme that does not call wp_body_open. Each one shows up in the page source. Check there before you change any settings. A short look at the source usually finds the cause in a minute.

Watch for these:

  • Two containers firing: Remove one method. I saw two loaders when a plugin and a manual snippet ran together.
  • Missing noscript block: Your theme may lack wp_body_open. Use GTM4WP’s footer placement or add the hook.
  • Old page from cache: Purge your cache plugin and CDN after you change the install. Our post on WordPress caching plugins covers how.
  • Tags fire in Preview but not live: You did not publish the container.
  • Ad blockers: Some visitors block gtm.js. Your counts will run a little low.

Best Practices for GTM on WordPress

Keep GTM tidy from day one, and it stays easy to run. Use one container per site and give every tag, trigger and variable a plain name. Publish each change with a short version note, and give team members only the access they need.

A few habits help:

  • One container: Do not add a second container for the same site.
  • Plain names: Name tags like “GA4 page view” so anyone can read the list.
  • Version notes: Write what changed each time you publish.
  • Least access: Give read or edit rights only to people who need them.
  • Quarterly clean-up: Delete tags and triggers you no longer use.

Write down where the GTM code lives, such as the plugin name or the snippet file. When a developer or agency takes over later, that single note saves an hour of searching.

Re-check the page source after any theme change or major update. A new theme can drop the wp_body_open call without a warning.

Conclusion

Now you know how to install Google Tag Manager in WordPress with a plugin or a snippet. Create a Web container, copy the ID and add it with GTM4WP, WPCode or a manual hook, never two at once.

Verify with the page source and Preview mode. Then add your Google Analytics tag and publish. Keep the container lean and re-check it after theme updates.

Frequently Asked Questions (FAQs)

Q1. Why would anyone use Google Tag Manager on WordPress?

GTM lets you add and change tracking tags without editing theme files. One snippet holds every tag, and you can test and publish changes from Tag Manager. That saves time when you run several tags or work with a marketing team.

Q2. Is a plugin or a manual install better for Google Tag Manager?

A plugin is easier because you enter only the container ID. A manual hook prints the script higher in the head, which matches Google’s advice. Choose a plugin unless you want that control and can edit a child theme safely.

Q3. Can I install Google Tag Manager without Google Analytics?

Yes, because GTM works on its own. It can deliver other tags, such as ad pixels or custom scripts. You only need a Google account and a container, and you can add Google Analytics later.

Q4. Does Google Tag Manager affect WordPress speed?

The container script loads asynchronously and does not block the page. The tags inside it add weight. A long tag list slows pages more than the container does. Measure your speed before and after each new tag.

Q5. How do I check that Google Tag Manager is working?

View the page source and search for gtm.js, which should appear once. Then click Preview in Tag Manager, enter your site address and click Connect. Tag Assistant shows which tags fired on the page.

Q6. Can I use GTM4WP and a manual snippet together?

No. In my test, running both printed two gtm.js loaders and two noscript blocks on one page. That can make tags fire twice and double your counts. Use one method only.

Yash Kapoor
Yash Kapoor

Yash Kapoor is the founder and WordPress expert at DevDiggers, where he builds WordPress and WooCommerce plugins for loyalty programs, point-of-sale systems, digital wallets and affiliate management. He writes about developer tools, site performance and the technical side of running a WordPress store. He draws on years of building and maintaining production plugin codebases.

Leave a Reply

Your email address will not be published. Required fields are marked *