How to Install Google Tag Manager on WordPress [VIDEO]

Google Tag Manager WordPress

Google Tag Manager (GTM) is a small piece of code that you can add to your WordPress site that allows you to add various other tracking scripts, remarketing tags, etc. to your site, all through an easy-to-use interface. Setup Google Tag Manager one time, and then add unlimited scripts to your website without ever touching another line of code. Pretty awesome, right? Especially for marketers and less technical site owners, GTM can provide immense value.

I’ll walk you through the process of installing Google Tag Manager on WordPress. Step-by-step instructions below the video.

1. Create a Google Tag Manager Account

The first thing we need to do is setup an account with Google Tag Manger.

1a. Setup Account

There are two levels of access with GTM: accounts & containers. An account should be thought of as your larger organization. A container is a specific website, or URL. One organization (account) might own and operate three different websites (containers). This follows Google’s recommendation.

  • Give your account a name

1b. Setup Container

Your container is the actual website that you want to add scripts to.

  1. Give your container a name. You should use your site’s domain name. Either www.yoursite.com or yoursite.com.
  2. Where to use container – Choose “Web”
    • If you were creating a mobile app, you would choose iOS or Android, for the appropriate operating system you were developing on
  3. Click “Create”  (and agree to the Terms of Service)

2. Install Google Tag Manager on WordPress

You should immediately be prompted with a modal window that contains your unique Google Tag Manager code. However, if you aren’t…

  1. In the top navigation, click “Admin”
  2. In the second column, under “Container,” make sure your container is displayed
  3. Further down that column, click “Install Google Tag Manager”
    • This will take you to a screen with your unique code
  4. Copy this code
Google Tag Manager WordPress - Find Install Code
Where to find your unique GTM install code

2a. Add Code to Your Theme

It is possible to add Tag Manager via a plugin, or an action hook that fires right after the opening <body> tag. However, one of the quickest & easiest ways to install GTM is placing the code in your theme’s header.php file.

If your theme does not have a header.php file, reach out to the theme developer and let them know what you’re trying to do. Ask them which file you need to update in order to insert code on every page, right after the <body> tag.

NOTE: If you switch themes, be sure to transfer this code to your new theme.

  1. Open up your favorite code editor. We use Sublime Text, but TextEdit (Mac) or Notepad (PC) will do the trick.
  2. Open your header.php file
  3. Search for <body
  4. Add your unique Google Tag Manager script on the next line, after the <body> tag
    • The code below has a fake GTM ID (GTM-ABC123). Be sure you copy the unique code from your admin area.
<body <?php body_class(); ?>>
<!-- Google Tag Manager -->
<noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-ABC123"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<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=
'//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-ABC123');</script>
<!-- End Google Tag Manager -->
  1. Then just upload this file to your server using an FTP program (FileZilla)

NOTE: If you’re using a theme that is updated frequently, you should definitely consider creating a child theme, and adding this to the header.php file of your child theme.


Two simple steps. Now that you have Google Tag Manager installed on your WordPress site, you’re ready to start adding tags. How about adding Google Analytics with Tag Manager as your first tag?

Please Share Your Thoughts

All fields are required. Your email will not be published.

Please use standard <code> and <pre> tags to post code examples.