Tag management systems help marketers track user activity on their website using code snippets. For WordPress website owners, tools like Google Tag Manager (GTM) allow you to manage and track pixels without needing a developer to update your code regularly.
This guide explores four methods for adding GTM to your WordPress site, how to verify your setup, and best practices for making the most of this software.
What is Google Tag Manager?
Google Tag Manager (GTM) lets you install and manage marketing tags — also known as pixels — directly from one dashboard, without touching your site’s code every time.
Pixels from tools like Google Analytics, Facebook Ads, and others track how people interact with your site, where they come from, and whether they take key actions like signing up or making a purchase.
Before GTM, adding these tags meant editing your website’s code manually. Now, you only need to add two GTM snippets during setup. After that, you can manage everything from your GTM account.
Note: the setup involves placing one snippet in the <head> of your site and the other right after the opening <body> tag.
What you need before you start
Before jumping into the ways to add GTM to your WordPress site, you’ll need the following:
- A Google Tag Manager account
- A container set up for your WordPress site
- The container’s GTM ID (formatted like this: GTM-XXXXXXX)
- Your GTM credentials (code snippets)
If you haven’t created a GTM account yet, Google’s Get Started with Tag Manager guide walks you through setting up your account, creating a container, and adding your website details.
Your GTM credentials will appear in a pop-up after setup. If they don’t, click your container’s GTM ID to bring the installation code back up — you’ll need it for some of the methods below.
Note: While the changes in this guide are minimal, it’s always good practice to back up your site before editing any code or introducing new plugins. Use a trusted backup tool like Jetpack VaultPress Backup to keep your data safe.
Method 1: Manually add the GTM code to theme files
For those who want complete control over their WordPress site, adding the GTM code directly to theme files is a solid option. This method is also helpful if you’re utilizing a custom theme or aiming to reduce plugin count for better performance.
Theme update risk:
Quality WordPress themes receive regular updates to address security and industry changes. Unfortunately, these updates can overwrite your GTM snippets. To avoid losing your setup, create a child theme to make these edits instead.
Instructions for classic themes
- In your WordPress dashboard, go to Appearance → Editor
- Open the header.php file of your active theme
- Locate the <head> tag
- Paste the head snippet of your GTM credentials
- Locate the <body>
- Paste the second snippet right after the <body> tag
Instructions for block themes
If your theme uses the Site Editor, you’ve probably noticed that there’s no header.php file. That’s because block themes use block templates instead of traditional PHP files. But don’t worry — you can still add GTM code manually using a small PHP workaround.
Safe coding practices
Editing your functions.php file can break your site if there’s a syntax error (even a missing semicolon). To stay safe:
- Back up your site using a tool like Jetpack VaultPress Backup.
- Don’t delete or overwrite anything unless you understand what it does.
- Test your site after saving. You can fix something through FTP or your hosting file manager if something goes wrong.
- Use a plugin like Code Snippets. This lets you add custom PHP code without touching your theme files and helps prevent fatal errors.
How to add GTM snippets
- In your WordPress dashboard, go to Tools → Theme File Editor. Or use FTP, SSH, or your hosting control panel to find /wp-content/themes/your-theme-name/functions.php
- Open your functions.php file
- Scroll just past the opening <?php and any comments or require_once() lines
- Add the following snippet to insert the head code (replace YOUR_VERIFICATION_CODE_HERE with the code Google gives you):
function add_sitekit_script_to_head() {
?>
<!-- Google Site Kit Verification Code -->
<meta name="google-site-verification" content="YOUR_VERIFICATION_CODE_HERE" />
<?php
}
add_action('wp_head', 'add_sitekit_script_to_head');
- To insert the body GTM snippet (replace GTM-XXXX with your GTM ID), add:
function add_gtm_after_body() {
?>
<!-- Google Tag Manager (noscript) -->
<noscript>
https://www.googletagmanager.com/ns.html?id=GTM-XXXX
</noscript>
<?php
}
add_action('wp_body_open', 'add_gtm_after_body');
- Save your changes

A note on the wp_body_open function:
The wp_body_open() function is what allows your functions.php snippet to output just after <body>. Most modern themes include this function, but some early block themes might not.
To check, look in your theme files for a call to wp_body_open(); — it’s usually in index.php or somewhere in the block template structure.
If it’s missing, you can add it manually to your block-templates/index.html like this:
<!-- wp:template-part {"slug":"header","theme":"your-theme-slug","tagName":"header"} /-->
<?php wp_body_open(); ?>
Editing code can feel intimidating, but once you know where to look, it gets easier. That said, if you’d rather avoid touching PHP altogether, there are plugins that simplify adding GTM to your theme.
Method 2: Use the Site Kit by Google plugin
Site Kit is Google’s official plugin for adding Google Analytics to WordPress, and integrating other Google products like Search Console and PageSpeed Insights. It’s a convenient option for adding Google Tag Manager, especially if you already use other Google tools.
Simple, yet powerful stats to grow your site
With Jetpack Stats, you don’t need to be a data scientist to see how your site is performing.
Get Jetpack StatsInstructions
- In your dashboard, go to Plugins → Add New
- Search for Site Kit by Google
- Click Install Now, then Activate
- Complete the setup by connecting your site to your Google account
- Once connected, go to Site Kit → Settings
- Under Connect More Services, click Set up Tag Manager
- If you already have an account and container, choose Re-fetch My Account. If you don’t have a GTM account, select Create an Account
- Pick your GTM account and container
- Click Confirm and Continue
Once connected, Site Kit automatically adds the GTM snippets to your site. There’s no need to touch your theme files or add anything manually. You can manage and add tags directly within the plugin interface.
Method 3: Use the GTM4WP plugin
The GTM4WP plugin offers more flexibility for placing your GTM code and customizing its functionality on your WordPress site.
In addition to GTM support, this plugin integrates with tools like WooCommerce, Contact Form 7, and Cookiebot. You’ll also get access to more detailed data tracking, the ability to blocklist or allowlist specific GTM tags, and experimental features for advanced setups.
Instructions
- In your WordPress dashboard, go to Plugins → Add New
- Search for GTM4WP
- Click Install Now, then Activate
- After activation, go to Settings → Google Tag Manager
- Under the General tab, enter your GTM Container ID (e.g., GTM-XXXXXXX)
- Choose where to place the GTM snippets. Select Off (no tweak, right placement) to avoid issues with Search Console verification
- Enable any additional features you’d like
- Scroll to the bottom and click Save Changes
Once set up, GTM4WP automatically injects the GTM snippets into your site and enables structured data tracking, among other advanced features.
Method 4: Use the WPCode plugin
WPCode is another plugin that lets you add code to your site without editing theme files.
The plugin features an intuitive interface and goes beyond header and footer injections for GTM, supporting custom HTML, JavaScript, CSS, and plain text snippets.
WPCode also includes a cloud library, making it easy for developers and agencies to save and reuse snippets across multiple sites.
Instructions
- In your WordPress dashboard, go to Plugins → Add New
- Search for WPCode
- Click Install Now, then Activate
- Once active, navigate to Code Snippets → Header & Footer
- Paste the first GTM code snippet under the Header section
- Paste the second GTM code snippet in the Body section
- Click Save Changes
WPCode does offer a paid plan with advanced features like smart conditional logic, expanded cloud snippet storage, and integrations with plugins like WooCommerce. However, the free version covers everything needed for adding GTM to your site.
How to verify your GTM installation
No matter which method you use to add Google Tag Manager to your WordPress site, it’s important to make sure everything is working as expected.
First, confirm that you’ve added at least one tag to your GTM container — Google Analytics is a common starting point. Then, follow these steps to verify your setup:
- In your GTM dashboard, click Preview
- Enter your WordPress site’s URL
- Click Connect and browse your site
- Check if your tags are firing as expected in the debug panel
Best practices for managing GTM in WordPress
Once your GTM setup is done and working, you likely won’t need to make frequent changes. Still, following these best practices can help you avoid common issues and keep your data accurate:
- Only use one GTM integration plugin to prevent compatibility issues
- Avoid adding duplicate tags, as they can skew your tracking data
- Test new tags using GTM Preview Mode before publishing them
- Keep your workspace organized by using clear, consistent names for tags, triggers, and variables
- Back up your WordPress site before making any changes to GTM settings or plugin configurations
See key metrics without leaving your WordPress dashboard
After setting up Google Tag Manager, you’ll have access to advanced tracking data — but sometimes, a quick snapshot of your site’s metrics is all you need.
That’s where Jetpack Stats comes in.
Jetpack Stats works seamlessly with Google Tag Manager. While GTM handles advanced tracking and custom tag deployment, Jetpack Stats gives you a fast, simplified view of key metrics right inside your WordPress dashboard.
Here’s what you can track with Jetpack Stats:
- Daily, weekly, and monthly site views
- Top-performing posts and pages
- Visitor engagement trends
- Search queries that drive traffic
- Outbound link clicks
- Referral sources, including social media
Jetpack Stats runs on WordPress by design, doesn’t require extra configurations, and integrates effortlessly with your existing setup. It’s a great fit for editors, contributors, or clients who want visibility into performance without diving into GTM.
By pairing Google Tag Manager with Jetpack Stats, you get both: deep insight when you need it and quick clarity when speed matters. Learn more about Jetpack Stats here.
Simple, yet powerful stats to grow your site
With Jetpack Stats, you don’t need to be a data scientist to see how your site is performing.
Get Jetpack Stats