How to Set Up Google Tag Manager in WordPress (Step by Step)

Set up Google Tag Manager in WordPress

As your blog grows, you add more tracking codes: Google Analytics, conversion pixels, heatmaps, ad platforms, and event tracking. Pasting each one into your theme gets messy fast. Google Tag Manager (GTM) is a free tool that lets you add and manage all these tags from one dashboard, without touching your site’s code again.

Do You Even Need Google Tag Manager?

If you only need Google Analytics 4, you may not need GTM; add GA4 directly with Site Kit or a plugin. GTM is worth it when you use several tracking tools or want to track events such as button clicks, form submissions, or affiliate link clicks without code.

Step 1: Create a GTM Account and Container

  1. Go to tagmanager.google.com and sign in with your Google account.
  2. Click Create Account, enter an account name (your business) and country.
  3. Enter a container name (your website) and choose Web as the platform.
  4. Accept the terms. GTM shows two code snippets: one for the <head> and one right after the opening <body> tag. Note your container ID, which looks like GTM-XXXXXXX.
Setting up a Google Tag Manager container

Step 2: Add GTM to WordPress

Choose one method:

Option A: GTM4WP (Recommended)

Install GTM4WP (700,000+ installs). Go to Settings > Google Tag Manager, paste your container ID, and save. It places both snippets correctly and can also push useful WordPress data (post type, category, author) to GTM.

Option B: Site Kit by Google

If you use Site Kit, connect the Tag Manager module and select your container. Site Kit handles the code for you.

Option C: WPCode

Install WPCode (formerly Insert Headers and Footers), go to Code Snippets > Header & Footer, paste the head snippet into Header and the body snippet into Body, and save.

Avoid editing your theme’s header.php directly; your changes disappear when the theme updates.

Step 3: Add Your First Tag (Google Analytics 4)

  1. In GTM, go to Tags > New.
  2. Click Tag Configuration and choose Google Tag.
  3. Enter your GA4 Measurement ID (it starts with G-).
  4. Under Triggering, choose Initialization – All Pages (or All Pages).
  5. Name the tag and save.

If GA4 is already installed by another plugin, remove that code first, or you will count every visit twice.

Step 4: Preview and Publish

  1. Click Preview in GTM, enter your site URL, and connect. Tag Assistant opens your site and shows which tags fired.
  2. Confirm your Google Tag fired on page load.
  3. Back in GTM, click Submit, add a version name, and click Publish.

Nothing goes live until you publish, which makes GTM safe to experiment with.

Useful Tags to Add Next

  • GA4 events for outbound or affiliate link clicks.
  • Form submission and button click tracking.
  • Microsoft Clarity for heatmaps.
  • Ad platform pixels (Meta, LinkedIn, Google Ads) if you run ads, with consent where required.

Frequently Asked Questions

Does Google Tag Manager slow down my site?

The GTM container itself is light, but every tag you add loads more code. Keep only the tags you use.

Is Google Tag Manager free?

Yes. The standard version is free.

Do I still need a cookie consent banner?

If you have visitors from the EU or UK and use tracking tags, yes. GTM supports Consent Mode to respect visitors’ choices.

Comments

6 responses to “How to Set Up Google Tag Manager in WordPress (Step by Step)”

Leave a Reply

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

  1. Bappi Avatar
    Bappi

    Hi, Istiak I read your blog from one year. I am inspired by you dear. Thanks for providing these good posts. I love your posts most because all your posts are to the point and not too lengthy like some others bloggers do for search engine ranking.

    Thanks.

    1. Istiak Rayhan Avatar
      Istiak Rayhan

      Thanks for your kind words. Let me know if you need any helps.

  2. Palash Avatar
    Palash

    Once upon a time, I was trying to create Google TAG Manager in my WordPress blog at Blogmehub, Real thing is that I cannot add it. But today I learned many things from this post about how to add Google TAG manager in a WP blog or website.
    Thanks Istiak

    1. Istiak Rayhan Avatar
      Istiak Rayhan

      Thanks Palash for being a regular reader. And glad to know that you found it helpful.

  3. Raaja Anandhan Avatar
    Raaja Anandhan

    Hi Istiak,

    Nice review about “Google Tag Manager”. May i know the purpose of using this in wordpress. I don’t know why we want to add Tag Manager to our blog.

    1. Istiak Rayhan Avatar
      Istiak Rayhan

      You can manage tags like conversion tracking, remarketing, gathering analytical data, event tracking etc by using Google Tag Manager.