• Categories
    • Tutorials
    • Beginners Guide
    • WordPress News
    • WordPress Security
    • Best WordPress Plugins
    • WordPress Themes
    • Product Reviews
    • WP Tips & Tricks
  • Guides
    • Start a Blog
    • Make a Website
    • WordPress Hosting
  • WordPress Hosting
    • A2 Hosting
    • HostGator
    • Bluehost
    • Cloudways
  • Managed Hosting
    • WPEngine
    • Rocket.net
    • WPX
    • Kinsta
  • Coupons
    • WPEngine
    • Flywheel
    • Cloudways
    • A2 Hosting
    • WPX Hosting
WordPress Tutorials

How To Add Google Tag Manager To WordPress And Create Your First Tag

Last Updated on: June 23, 2018 Colin Newcomer 3 Comments

How To Add Google Tag Manager To WordPress And Create Your First Tag

Want to add Google Tag Manager to WordPress?

Google Tag Manager has a ton of benefits for WordPress sites. It helps you add and manage all the various scripts you use on your site. For example, instead of needing to manually add code for services like:

  • Google Analytics
  • Event tracking
  • Google Optimize

You can just manage everything through Google Tag Manager!

If you find yourself often adding various scripts to your WordPress site, Google Tag Manager is going to be a lot more convenient for you. And once you get the hang of it, you can even start using it to collect more actionable data to inform your marketing efforts.

In this post, I’ll show you step-by-step how to install Google Tag Manager on your WordPress site, including where to add the code.

Then, I’ll give you a quick guide for how you can publish your first tag and make sure it’s working.

Let’s dive in!

Step 1: Sign Up For A Google Tag Manager Account

If you haven’t already, the first thing you need to do is sign up for a free Google Tag Manager account.

You can do that by heading here.

Once you sign up, you should be in the Add a New Account interface. Give your company a name:

sign up for gtm

Then, in the Setup Container section, enter your website’s name in the Container name field and choose Web:

configuire container

Once you accept Google’s Terms of Service, Google should take you to the Google Tag Manager interface and show you two code snippets. Keep this window open because you’ll need to add both of these code snippets to your WordPress site in the next section:

google tag manager code snippets

Step 2: Add Google Tag Manager Code Snippets To Your Site

This is the one part that’s kind of tricky. Previously, you only had to add one code snippet to your theme’s <head> section, but now Google Tag Manager wants you to add two snippets:

  • The first one goes in your <head> section
  • The second one goes right after the opening <body> tag

Beyond directly editing your child theme, WordPress doesn’t give you an easy way to insert code after the <body> tag, and each theme works a little differently so I can’t give you a tutorial that applies to all themes.

So:

  • If you already feel comfortable editing your child theme’s files directly, you can just do that.
  • If you don’t feel comfortable working directly with your theme’s files, I’ll show you two different methods that you can use – a beginner-friendly plugin and a simplified code method.

Option 1: Use Head, Footer and Post Injections

If you’re ok with dedicating a plugin to Google Tag Manager, the easiest way to add it is using the free Head, Footer and Post Injections plugin.

To get started, install and activate this free plugin. Then, go to Settings → Header and Footer in your WordPress dashboard to access the plugin’s interface.

Now:

  • Paste the first Google Tag Manager code snippet into the ON EVERY PAGE box in the <HEAD> PAGE SECTION INJECTION section
  • Paste the second Google Tag Manager code snippet into the DESKTOP* box in the AFTER THE <BODY> TAG section (don’t worry – the code snippet will still load on mobile. Head, Footer, and Post Injections just makes it possible to use separate code snippets if you check the mobile box)

It should look like this:

how to add google tag manager to wordpress - where to put code

Make sure to save your changes and you’re all done!

Option 2: Use A Functions.php Code Snippet

Let me lead by saying that this method is technically not 100% optimal. It works fine for most sites, but I’ll explain what I mean after I show you what to do.

To use it, all you need to do is add this code snippet to your child theme’sfunctions.php file:

add_action('wp_head', 'gtm_head_code');
Function gtm_head_code(){
?>
FIRST_SCRIPT_FROM_GTM_INTERFACE
<?php
}
add_action('wp_footer', 'gtm_body_code');
Function gtm_body_code(){
?>
SECOND_SCRIPT_FROM_GTM_INTERFACE
<?php
}

Make sure to replace the placeholders with the actual code snippets.

So why isn’t this method 100% optimal?

Because this method puts the second code snippet in the footer, rather than after the opening <body> tag, your tag might not fire if a visitor doesn’t completely load your page (which is rare, but possible). That’s the reason Google recommends you add it as high up in your site’s code as possible.

But for most sites? This method is totally fine.

Step 3: Test To Make Sure Your Snippets Are Working

To make sure you properly installed Google Tag Manager:

  • Go to the free GA Checker tool
  • Enter your website’s URL
  • Click Check Your Site

Go to the Tag Manager tab of the results and look for the green checkbox in the Tag Manager column:

test tag manager

If you see it – congrats! You properly installed the Google Tag Manager scripts on your WordPress site.

Now, I’ll quickly go through how to use Google Tag Manager to create your first tag.

Step 4: Create Your First Tag

Once you’ve added the code snippets to your site, you can go back to the Google Tag Manager interface and create your first tag.

A “tag” is basically a specific script that you want to insert into your site with Google Tag Manager.

To get started, create a New Tag in your Google Tag Manager dashboard:

create tag

By clicking on Tag Configuration, you can choose what type of tag to create. Google includes all kinds of pre-built options for stuff like Google Analytics, Google Optimize, and lots of third-party services.

But you can also use the Custom HTML or Custom Image tags to insert any client-side code:

choose tag type

Once you choose your Tag Type, you’ll need to configure it following the settings.

Then, you can click on the Triggering section to choose when to “fire” your tag.

The default is All Pages, but you can also get a lot more targeted if you want by clicking on the + icon:

trigger

Once you finish setting things up, click Save.

Step 5: Publish Your Container

Now, all you need to do to make your tags live is publish your Container.

To do that, click on the SUBMIT button in your Google Tag Manager interface:

submit

Then, enter a Version Name and Version Description. I recommend that you make these as detailed as possible to help with version control later on. That is, explain exactly which tags you’ve added and what they do.

Then, click PUBLISH:

publish container

And that’s it! You just published your first tag.

How To Test If Individual Tags Are Firing

If you want to make sure the individual tags in your container are firing, Google offers a free browser extension for Chrome called Tag Assistant.

Resources To Help You Become A Google Tag Manager Pro

At this point, you’ve successfully added Google Tag Manager to WordPress. But Google Tag Manager is pretty deep in functionality and explaining the huge number of interface options goes beyond the scope of this post.

So – now that you have Google Tag Manager installed, you can learn a whole lot more about the interface in this Moz article.

And for more related reading on some of the tags you can implement in Google Tag Manager, check out our posts on Google Analytics and WooCommerce Google Analytics goals.

+ Share
Disclosure

Colin Newcomer

Colin Newcomer is a WordPress writer for WPKube. He uses WordPress more often than any sane person should.

Related Posts

Back to all articles
  • Dealing with WordPress RSS Feed Errors: How to Identify and Fix Them

    Dealing with WordPress RSS Feed Errors: How to Identify and Fix Them

  • What is WordPress? A Beginner's Guide!

    What is WordPress? What Can it do & Is it Right for You? A Beginner’s Guide

  • How to Set Up WordPress Two-Factor Authentication: WP 2FA Review

    How to Set Up WordPress Two-Factor Authentication: WP 2FA Review

Coupons

View more deals
  • WordPress.com Coupon Discount Code
    30% OFF

    WordPress.com Coupon

    WordPress.com is a fully hosted website builder that lets you cre
    Get This Deal
  • WP 2FA Coupon
    20% OFF

    WP 2FA Coupon

    Security should be at the forefront of all site owner’s min
    Get This Deal
  • 10% OFF

    Elegant Themes Coupon

    You can’t move within WordPress circles without coming across E
    Get This Deal
3 Comments Leave a Reply
  1. Gil says

    May 23, 2019 at 2:52 pm

    After checking so many alternatives – the php option (options 2) seems to be the only one that worked for me. Thanks!

    Reply
  2. Henry Garcia says

    June 4, 2019 at 9:21 pm

    This was great! It helped me a lot, I used the plugin option.

    Reply
  3. Mayur Gaikwad says

    August 13, 2019 at 10:02 am

    Amazing information that helped me set GA tags on my new website.

    Reply

Leave a Reply Cancel reply

Full Disclosure This post may contain affiliate links, meaning that if you click on one of the links and purchase an item, we may receive a commission (at no additional cost to you). All opinions are our own and we do not accept payments for positive reviews.

Our Newsletter

Get awesome content delivered straight to your inbox.

Thank you!

You have successfully joined our subscriber list.

.

THE BEST OF WPKUBE

Some of the best content we have published so far.

BEGINNER GUIDES & REVIEWS

110 Best WordPress Hosting Options Tested for 2025
28 Best Managed WordPress Hosting Providers for 2025 Compared
38 Best Cheap WordPress Hosting Providers in 2025 (From $1.99)
46 Best WordPress LMS Plugins – Detailed Comparison & Review for 2024
55 Best WooCommerce Hosting Providers Compared in 2025 (All Budgets)
66 Best WordPress Landing Page Plugins Compared + Recommendations (2024)
79 Best List Building Plugins for WordPress In 2024
8How to Fix the 500 Internal Server Error on Your WordPress Website
9Beaver Builder Review: Honest Thoughts + Pros and Cons (2025)
10OptimizePress Review: Create Landing Pages with Ease
11How to Make a Website: Complete Beginner’s Guide
12Top 22 Best Free Stock Photo Resources For Your Site
13How to Start a Blog in 2022 (Step by Step Guide)
14How To Fix ‘503 Service Unavailable’ WordPress Error
1511 Best Contact Form Plugins for WordPress in 2025
16How to Add a Custom Logo to Your WordPress Site
17How to Fix Error Establishing a Database Connection in WordPress

Cloudways: 30% OFF Deal

Save 30% on one of the best cloud hosting providers.

Get this Deal
Featured In Forbes Huffpost Entrepreneur SEJ

About WPKube

WPKube is an online WordPress resource which focuses on WordPress tutorials, How-to’s, guides, plugins, news, and more. We aim to provide the most comprehensive beginner’s guides to anything about WordPress — from installing plugins, themes, automated installs and setups, to creating and setting up pages for your website.

We have over 500+ tutorials, guides, product reviews, tips, and tricks about WordPress. Founded by Devesh Sharma, the main goal of this site is to provide useful information on anything and everything WordPress.

Twitter Facebook

Useful Links

  • Behind the Scenes
  • Beginner Guides
  • WordPress Hosting
  • WooCommerce Themes
  • MeridianThemes
  • Exclusive WordPress Deals
View All Guides »

Reviews

  • WPEngine 33% OFF
  • WPX Hosting
  • Flywheel 33% OFF
  • Divi Theme 20% OFF
  • Systeme.io
  • Elegant Themes
Reviews »

Deals

  • InMotion Hosting
  • LifterLMS Coupon
  • LiquidWeb Coupon
  • WPEngine Coupon
  • A2 Hosting
  • Solid Affiliate
More Deals »
© Copyright 2023 WPKube ® All Rights Reserved.
  • Contact
  • Site Terms
  • Disclosure
  • Privacy Policy