How to set up and install Google Tag Manager on WordPress
This step-by-step guide will help you get started with Google Tag Manager. You may be wondering how to create an account or a container, or perhaps you already have one and need to install it on your WordPress, Squarespace, or Wix website. Well, you’re in the right place. I have well over 100 completed projects as a Google Tag Manager consultant under my belt, and everything that you will find in this guide was thoroughly tested.
Create Your Google Tag Manager Account
Creating a Google Tag Manager account is simple and it will take you 1 minute. To create an account go to https://tagmanager.google.com, where you will see this if you don’t have an account yet:

- Click Create Account
- Give the account a name
- Select your country
- Give the container a name
- Select Web as the platform
- Click Create

Pretty straightforward, right?
Once the creation is completed, the new Google Tag Manager container will be opened, and you will be greeted with a popup with the code you’ll need to install on your website:

Here you will see two code snippets that you need to install on your website:
- The first (primary code) should be added to the
<head>section. - The second (secondary code) one should be added to the
<body>section.
In the ideal these two snippets should be placed right after the opening tags. In reality, you usually don’t have that granular control. Google Tag Manager will work regardless of where you put the snippets, but the higher the code is placed, the more accurate your tracking tags will be because they will be executed earlier.
One thing that not many people know is that you actually need only the primary code snippet added to the <head> section. The second snippet is for users who have JavaScript disabled in their browsers, which nobody does. This doesn’t mean you don’t have to add both. But if your website platform only allows you to inject custom code into the <head> section, it will do the job just as well. As a matter of fact, even if you put the main code anywhere, it will still work.
“I closed the popup. Where can I find the Google Tag Manager code?”
Whenever you need to get the Google Tag Manager code snippets again, you can simply click on the container ID, and the popup with the code will reappear.

Depending on the website platform you are using, the installation process will be different. Here are two typical scenarios:
- You manually install the GTM code snippets by copying and pasting them.
- You simply enter only the GTM ID in the designated field in the website settings.
Install Google Tag Manager on WordPress
When it comes to WordPress, you have many options available. But before exploring them, check whether your current theme or installed plugins already support Google Tag Manager.
Add GTM to a WordPress website using the Insert Headers And Footers plugin
There are many plugins that will allow you to add any custom code to both the <head> and <body> tags, one of which is Insert Headers And Footers by WPBrigade (the old name is WP Headers and Footers):

Once this plugin is installed and activated, open the WordPress admin dashboard (yourwebsite.com/wp-admin), go to Settings → WP Headers and Footers. You will see three empty code sections:
- Scripts in Header
- Scripts in Body
- Scripts in Footer

We want to put our GTM code for the <head> tag to Scripts in Header and put our GTM code for the <body> section to Scripts in Body. We won’t need Scripts in Footer because we want to ensure that our Google Tag Manager code is as high in the website source code as possible, remember?
Once you save the changes, let’s check how it works. The fastest way would be to open the website and view the website source code (right mouse button click → View Page Source or use shortcuts: command + option + u on Mac and ctrl + u on PC). In the source code, search for GTM- and you should find two instances of your Google Tag Manager ID: one in the <head> section and the other in the <body> section:

On my screenshot, you can see that the <head> section code snippet is on line #153, which is not ideal. Fortunately, the plugin allows us to fix that. Let’s reopen it and go to the second tab, called Settings.

Set Header’s Priority to 1. This will place our GTM code as high as possible in the <head> section. Now, if we save the changes, refresh the page, and check the source code once again, we will see that our main GTM code is now much higher in the source code:

Add GTM to a WordPress website using the GTM4WP plugin
Another quite popular plugin for installing Google Tag Manager on WordPress websites would be GTM4WP by Thomas Geiger:

Once you install GTM4WP, open the WordPress admin dashboard, go to Settings → Google Tag Manager.

In the General tab settings, add your container ID, enable the container code, and you’re done.
But adding the container code is just the tip of the iceberg. The real beauty of GTM4WP is that it also captures a lot of extra data, enabling e-commerce tracking (Woo), form submission tracking (Contact Form 7), etc. This is my typical go-to plugin for any WordPress website.
To ensure early container loading, you can enable this setting under the Advanced tab:

Add GTM to a WordPress website using the Google Site Kit plugin

Another option is to use Google Site Kit, the official plugin developed by Google. It allows for seamless integration of your WordPress website with Google products, including Google Analytics, Google Search Console, and of course, Google Tag Manager.
I used this plugin when it was just launched around 2020. One thing some might find nice, but I do not, is that it is too simple and doesn’t give much control. The plugin doesn’t require even inputting the container ID. All you need to do to install Google Tag Manager is to authorize Google, and it will pick up all of your GTM containers, so you only have to select which one belongs to your website. Pretty simple.
Add GTM to a WordPress website without plugins
Okay, so you’re not a fan of plugins and you want to do things the hard way. I hear you. There are two options for you.
Add the code to the theme header file
In the Appearance settings open Theme File Editor and in the right sidebar find the Theme Header file (usually it’s called header.php):

Find where the opening <head> tag is and put your GTM code right after it. Repeat this process for the <body> code snippet and you’re done. Works like a charm:

Add the code to the theme functions.php
I don’t think anyone would use it, but it’s another alternative how you can install Google Tag Manager container code on a WordPress website. In Theme File Editor find functions.php and add the following code there:
function gtm_header_code() {
echo "
<!-- 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-XXXXXXXX');</script>
<!-- End Google Tag Manager -->
";
}
add_action('wp_head', 'gtm_header_code');
function gtm_body_code() {
echo '
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXXXXX"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->
';
}
add_action('wp_body_open', 'gtm_body_code');
Don’t forget to replace GTM-XXXXXXXX with your actual container ID.
Install Google Tag Manager on Wix

Wix has a native integration with Google Tag Manager, so you don’t have to mess around with codes. Go to Settings → Marketing Integrations (in the Advanced section) → Google Tag Manager → click Connect. You will be prompted to enter the GTM container ID, and Wix will take care of the rest.
Install Google Tag Manager on Squarespace

Squarespace doesn’t offer a dedicated GTM setting, so you will have to go to the code injection settings: Website → Pages → Website Tools (scroll to the bottom) → Code Injection. The main container code goes in the Header section, and the other one goes in the Footer section. Yes, footer is far from the opening <body> tag, but it’s not critical, and we don’t have a choice, anyway.
Install Google Tag Manager on Webflow

Go to the Webflow dashboard and select Custom code in the left menu. Here you will see two sections: Head code and Footer code. We put our main code snippet in the first one and the <body> code snippet in the second one. Similarly to Squarespace, we don’t get to position our code, but it will work just fine.
How to Check If Google Tag Manager Is Working
Apart from simply checking the page source code to see whether the GTM code is indeed added or not, there is another way. In the Tag Manager interface click the preview button:

It will open https://tagassistant.google.com, where you will be prompted to enter your website URL:

Once done, a new tab will be opened in the preview mode. And if you go back to the Tag Assistant tab, you should see something like this:

You should always prioritize this checking method over checking the page source code, as there might be a slip in the code that you won’t notice, resulting in errors. But the preview mode will tell you if anything is wrong with the installation.
Google Tag Manager Account Structure
Let me clarify the structure that Google Tag Manager uses. So, we’ve created our account and container, which are two different property levels in Google Tag Manager.

Account, essentially, is a folder, where your create containers. There are few, if any, interesting settings at the account level, except for User Management settings.
Containers, in their turn, is where all the Google Tag Manager magic happens. Here you create variables, triggers, and tags. It’s the container code you install on the website, not the account code.
The main reason I’m writing about the account-container relationship is that you need to know how it works, because once the container is created, you cannot transfer it from one account to another.
There is an export-import feature in Google Tag Manager that allows you to copy and paste the setup, which can help a lot if you ever have to reorganize the structure. But keep in mind, it will be a new container you’ll be moving the setup to; thus, you’ll need to replace the old Google Tag Manager code snippets with the new ones on your website.
How to structure containers in GTM
If you are setting up Google Tag Manager for a single company that you own or work for, chances are you will not need more than one account. When your company runs multiple websites, you typically use either a single GTM container with a cross-domain tracking setup for all websites, or multiple GTM containers for each website nested under the same account.
| Account | Container |
|---|---|
| Acme | Acme’s website #1 |
| Acme’s website #2 | |
| Acme’s website #3 |
If you are setting up Google Tag Manager for different companies that have nothing in common except you as the Google Tag Manager person, you want each business to have its own account.
| Account | Container |
|---|---|
| Client A | A’s website #1 |
| A’s website #2 | |
| Client B | B’s website |
| Client C | C’s website |
We want to have a well-thought-out structure because otherwise it will screw up the user management process.
How to create new GTM containers
To create second and subsequent containers, go to the Google Tag Manager homepage, where you will see your account and the nested container(s). Click on the three dots icon and select Create Container:

You can also create a new container if you go to the Admin tab and click the plus icon:

How to remove old GTM containers
If you want to delete a container from the account, go to the Admin tab in the top menu and click on Container Settings. In the appearing window, click the three-dot icon and select Delete.

To remove the entire account, do the same, but instead of going to Container Settings, go to Account Settings.

Both removed accounts and containers are put in the Trash Can (visible on the Tag Manager homepage), from where they are completely removed after 30 days.
What next
Once your Google Tag Manager account has been created, it’s the perfect time to add new users for collaboration on the account setup.
Also see my Google Analytics setup guide. You will find instructions on how to create an account, set up a property, and install Google Analytics on your website using Google Tag Manager.

Hi! I’m Roman, a Google Ads freelancer. This is my website where I share all kinds of things I find interesting related to Google Ads, Google Tag Manager, and Google Analytics. I am also available for hire, so if you need help with any of these, feel free to get in touch.