close modal
Enter your Email to get Free SEO tips
go to top

Adding Google Tag Manager to a WordPress Site

Adding Google Tag Manager to a WordPress Site
Add Google Tag Manager to a WordPress site.

Goal: To add Google Tag Manager to a WordPress site.

Ideal Outcome: Google Tag Manager is properly installed without any technical issues.

Prerequisites or requirements: This exact process only applies to WordPress.org sites.

Why this is important: Google Tag Manager is a great tool to add and manage multiple pixels and tracking codes without needing to edit the code of a site.

Where this is done: In your WordPress install and Google Tag Manager.

When this is done: Only once—the first time you install Google Tag Manager. 

Who does this: The person responsible for website management or analytics.

  • Environment Setup

Important: This SOP works only for self-hosted WordPress sites, aka WordPress.org and not WordPress.com

  1. Download the Google Tag Assistant Legacy Chrome Extension (Free).
  2. Sign up for Google Tag Manager (Free):
  1. You’ll need to log in to your Google account.
  2. If this is your first time creating a Google Tag Manager Account, you’ll be redirected to the account creation page.
  1. Fill in the following information:
  1. Account Name — The name you use to identify this account.
  2. Country — Country origin.
  3. Container name — Insert the URL of your website
  4. Target platform — Where do you plan to add Google Tag Manager (e.g. on your website, mobile, etc)
  5. (Optional) Share data anonymously with Google.
Creating a Google Tag Manager Account
  1. Once finished. Click “Create”.
  2. You’ll see a Google Tag Manager Terms of service pop up. Select the checkbox and click “Yes”.
Google Tag Manager Terms of Service
  1. You will see the code to install Google Tag Manager. Ignore this since you won’t be manually adding code to your Wordpress site. Click “OK”. 
  2. Once you are in your Workspace, make note of your Google Tag Manager ID.
Making note of Google Tag Manager ID
  • Click on Submit > Publish > Continue to publish your Google Tag Manager container
Publish Google Tag Manager container
  • Install and configure the Google Tag Manager WordPress plugin
  1. Log into your WordPress site.
  2. In the WordPress sidebar, go to Plugins > Add New
  3. Enter “Google Tag Manager for WordPress” in the search box
  4. Install the GTM4WP plugin (the image may vary)
Install Google Tag Manager WordPress plugin

       5. Activate the plugin

        6. In the WordPress sidebar, go to Settings > Google Tag Manager

       7. Paste your Google Tag Manager ID (the one you got from the Google Tag Manager dashboard) in the available field

Pasting Google Tag Manager ID

       8. The plugin offers several ways to install the container code on your site. Before you implement any of these, we recommend you create a backup of your site. 

  1. Option 1: Off — with this option, the plugin will try to figure out the right placement for the container for you. This is the easiest option but there’s a small risk it might break something on the frontend of your site. If you decide to go with codeless injection, select this option from the list and click “Save changes”
Off-Figureout Right Placement Container
  • After selecting this, visit the website in a new tab or window and make sure everything looks right. If it does, you can move on to the next step of QA-ing the installation.
  • Option 2: Manually Coded — with this option, you will need to make a small edit to your theme files. If your WordPress theme allows you to make changes and you’re comfortable with the theme editor, you can use this option. Select the “Custom (needs tweak in your template)” container code placement and click on “Save Changes.”
Manually Coded —Need to make a small edit to your theme files
  1. Copy the php code provided by the plugin and click on “Save Changes”
php code
  • In the WordPress sidebar, go to Appearance > Theme Editor
  • Make sure that you are editing the Theme that you currently have installed in your site (you can go to Appearance > Themes to check the name of the theme you are using)
Editing Theme
  • Select the “Theme Header” template from the list on the right.
Theme Header
  • This template is different depending on the theme that you have installed. However, you will alway be able to find an opening <body> tag in the code.
Body tagc
  • Paste the php code provided by the plugin right below the opening <body> tag.
Pasting php code
  • Click on “Update File”
  • QA your installation
  1. Open your website homepage using Chrome.
  2. Click on the Google Tag Assistant Chrome Extension
Google Tag Assistant Chrome Extension

       3. Click on “Enable”

Enable Google Tag Assistant

       4. Refresh the page and click on the Google Tag Assistant Chrome Extension again

       5. You should see a green tag for Google Tag Manager, indicating that the installation was successful.

Result of Tag Analysis


Related Blog Posts

Are You a Contractor Struggling to Get  Quality Leads?

Contact US
Muhammad Ali - Webflow Developer

Ready to speak with an expert?

500+

Websites Launched

200+

Clients Worldwide

10+

Years of Experience

By clicking “Accept All Cookies”, you agree to the storing of cookies on your device to enhance site navigation, analyze site usage, and assist in our marketing efforts. View our Privacy Policy for more information.