Google Tag Manager (often referred to as “GTM”) is a powerful tool that enables website owners to manage various tracking codes/tags without directly editing their website’s code. If you’re using WordPress, integrating Google Tag Manager is a relatively straightforward process. In this article, we will guide you through the step-by-step process of setting up Google Tag Manager on your WordPress website by installing the code in the theme files.
Create a Google Tag Manager Account
The first step is to create a Google Tag Manager account if you don’t already have one. Visit the Google Tag Manager website (tagmanager.google.com) and sign in using your Google account credentials. Once logged in, you can create a new tag manager account and/or container for your WordPress website.
Generate the Google Tag Manager Container Code
After creating a container, you will be provided with two code snippets: one for the head section of your website and another for the body section. The code for the body should appear directly below the opening body tag. The code for the head section should go as high in the head section as it is possible to put it, however, you will typically want to load in functional code on your website prior to the GTM code in the <head> tag.
If you navigate away from the container code it can be found by navigating to Admin > Container > Install Google Tag Manager


Install Google Tag Manager Code In The WordPress Theme Files
We can add the code for the head and body tags from the previous step directly into the WordPress theme files. When editing a WordPress theme, it is best practice to always use a child theme and edit the child theme files. Not using a child theme means that when the theme updates, it could risk removing the edits you have made to the code, using a child theme solves this issue and will keep the edits you make whilst also inheriting updates from the parent theme. You can read more about how to use child themes here.
Within your WordPress dashboard, navigate to Appearance > Theme file editor.

Navigate to the theme file “header.php”
Then paste the code for the head script and body script in the respective locations highlighted below.

Once the code has been pasted in, remember to click the button in the bottom left to update the file and save the changes.
Checking Tag Manager is Installed Correctly
After adding any code to the website or even for tags within Google Tag Manager, it is always a good idea to check your changes are working correctly and as expected.
The simplest way to check that Google Tag Manager is installed correctly is by navigating to Google Tag Manager and going to the preview on the container you have just installed.
By navigating to Workspace > Preview (in the top left) we can check if it’s working.

Then select “Connect” to the website.

It should then display a message on both the debug window and in the bottom right corner of the website window to show that Tag Manager has successfully connected. This indicates that Tag Manager is installed on your website.


No Comment! Be the first one.