コンテンツへスキップ
Jetpack

個別の製品

セキュリティ
VaultPress Backup Scan Akismet Anti-spam
パフォーマンス
サイト検索 Boost VideoPress
成長
Stats ソーシャル ニュースレター SEO Blaze CRM
管理
Manage モバイルアプリ

製品バンドル

Pro WordPressサイト向けのセキュリティ、パフォーマンス、成長支援ツールです。 完了 より高いサービス上限を備えたJetpackの全機能。
料金
概要 Jetpack AI がサイトにできること スキル エージェントに WordPress のスーパーパワーを ドキュメント AI エージェントの接続と設定 はじめに ChatGPT、Claude、コーディングエージェントを接続 比較 Jetpack と他の WordPress MCP コネクタの比較

エージェントを接続しよう。無料です。

ChatGPT や Claude を接続して、サイトの運営を任せましょう。有料プランは不要です。

ChatGPT 版を入手 (新しいタブで開きます) または Claude を使う (新しいタブで開きます)
サポート チームによるガイドとサポート ドキュメント Jetpack の各機能の使い方ガイド 機能リクエスト Request features and vote on ideas ブログ ニュース、製品の最新情報、使い方ガイド
概要
ログイン 始める
セキュリティ
VaultPress Backup Scan Akismet Anti-spam
パフォーマンス
サイト検索 Boost VideoPress
成長
Stats ソーシャル ニュースレター SEO Blaze CRM
管理
Manage モバイルアプリ

製品バンドル

Pro 完了
料金
概要 Jetpack AI がサイトにできること スキル エージェントに WordPress のスーパーパワーを ドキュメント AI エージェントの接続と設定 はじめに ChatGPT、Claude、コーディングエージェントを接続 比較 Jetpack と他の WordPress MCP コネクタの比較

エージェントを接続しよう。無料です。

ChatGPT や Claude を接続して、サイトの運営を任せましょう。有料プランは不要です。

ChatGPT 版を入手 (新しいタブで開きます) または Claude を使う (新しいタブで開きます)
サポート チームによるガイドとサポート ドキュメント Jetpack の各機能の使い方ガイド 機能リクエスト Request features and vote on ideas ブログ ニュース、製品の最新情報、使い方ガイド
概要 検索
ログイン 始める

ブログ / Jetpack 101

How to Add Google Tag Manager to WordPress (4 Methods)

Jen Swisher のアバター

Jen Swisher 7月 25, 2025 · 読了時間の目安: 8分


このページの内容

  1. TL;DR
  2. What is Google Tag Manager?
  3. What you need before you start
  4. Method 1: Manually add the GTM code to theme files
  5. Method 2: Use the Site Kit by Google plugin
  6. Method 3: Use the GTM4WP plugin
  7. Method 4: Use the WPCode plugin
  8. How to verify your GTM installation
  9. Best practices for managing GTM in WordPress
  10. See key metrics without leaving your WordPress dashboard

読了時間の目安: 8分

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.

TL;DR

  1. Create a Google Tag Manager account and web container before editing WordPress.
  2. Copy both GTM snippets from the container installation instructions.
  3. Use a GTM plugin when you want the safest WordPress-specific installation path.
  4. Use a header and body code placement plugin when you need manual placement without editing theme files.
  5. Edit theme files only with a child theme, backup, and a clear update plan.
  6. Use GTM Preview mode and Tag Assistant to confirm the container loads on the site.
  7. Publish the GTM container only after tags, triggers, and variables have been tested.
  8. Document who controls GTM access, because incorrect tags can affect analytics, ads, consent, and site behavior.

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

  1. In your WordPress dashboard, go to Appearance → Editor
  2. Open the header.php file of your active theme
  3. Locate the <head> tag
  4. Paste the head snippet of your GTM credentials
  5. Locate the <body>
  6. 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

  1. 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
  2. Open your functions.php file
  3. Scroll just past the opening <?php and any comments or require_once() lines
  4. 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');
  1. 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');
  1. Save your changes
Editing the functions.php file

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.

Instructions

  1. In your dashboard, go to Plugins → Add New
  2. Search for Site Kit by Google
  3. Click Install Now, then Activate
  4. Complete the setup by connecting your site to your Google account
  5. Once connected, go to Site Kit → Settings
  6. Under Connect More Services, click Set up Tag Manager
  7. 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
  8. Pick your GTM account and container
  9. 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

  1. In your WordPress dashboard, go to Plugins → Add New
  2. Search for GTM4WP
  3. Click Install Now, then Activate
  4. After activation, go to Settings → Google Tag Manager
  5. Under the General tab, enter your GTM Container ID (e.g., GTM-XXXXXXX)
  6. Choose where to place the GTM snippets. Select Off (no tweak, right placement) to avoid issues with Search Console verification
  7. Enable any additional features you’d like
  8. 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

  1. In your WordPress dashboard, go to Plugins → Add New
  2. Search for WPCode
  3. Click Install Now, then Activate
  4. Once active, navigate to Code Snippets → Header & Footer
  5. Paste the first GTM code snippet under the Header section
  6. Paste the second GTM code snippet in the Body section
  7. 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:

  1. In your GTM dashboard, click Preview
  2. Enter your WordPress site’s URL
  3. Click Connect and browse your site
  4. 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.

いいね 読み込み中…
Jen Swisher のアバター

Written by

Jen Swisher

Jen is a Customer Experience Specialist for Jetpack. She has been working with WordPress and Jetpack for over a decade. Before starting at Automattic, Jen helped small businesses, local non-profits, and Fortune 50 companies create engaging web experiences for their customers. She is passionate about teaching others how to create on the web without fear.

サイトの成長に役立つ、シンプルでパワフルな統計情報

Jetpack Statsなら、データサイエンティストでなくてもサイトのパフォーマンスを確認できます。

Jetpack Statsを入手

Questions about this post? Ask in the support forum

シェア


Keep reading.

More from Jetpack 101, newest first.

すべての投稿を見る

Jetpack 101 3月 31, 2026

WordPress Image SEO: 12 Techniques to Rank Higher & Load Faster

Are images helping or hurt…

Jen Swisher のアバター Jen Swisher 読了時間の目安: 14分

Jetpack 101 3月 26, 2026

WordPress Site Redirecting to Spam? Here’s How to Fix a Hacked Site

Uncover hidden malware, re…

Jen Swisher のアバター Jen Swisher 読了時間の目安: 12分

Jetpack 101 3月 24, 2026

WordPress Form with File Upload: How to Create One in 3 Steps

How to create a secure fil…

Jen Swisher のアバター Jen Swisher 読了時間の目安: 5分

AI ファーストで WordPress サイトを運営しよう。

Free to start, and AI agents are free to connect. Money back within 14 days on yearly plans.

始める Jetpack を無料で入手

WordPress プラグイン

  • Akismet アンチスパム↗ (新しいタブで開きます)
  • Jetpack↗ (新しいタブで開きます)
  • Jetpack ブースト↗ (新しいタブで開きます)
  • Jetpack CRM↗ (新しいタブで開きます)
  • Jetpack プロテクト↗ (新しいタブで開きます)
  • Jetpack 検索↗ (新しいタブで開きます)
  • Jetpack ソーシャル↗ (新しいタブで開きます)
  • Jetpack VideoPress↗ (新しいタブで開きます)
  • VaultPress バックアップ↗ (新しいタブで開きます)
  • WP Super Cache↗ (新しいタブで開きます)
  • ダウンロード

AI

  • Jetpack AI
  • スキル
  • WordPress MCP

パートナー

  • パートナープログラム
  • おすすめのホスティング事業者
  • ホスティング事業者向け
  • 代理店向け
  • アフィリエイト向け

開発者

  • ドキュメント↗ (新しいタブで開きます)
  • ベータプログラム
  • GitHub の Jetpack↗ (新しいタブで開きます)

ヘルプ

  • ナレッジベース
  • フォーラム↗ (新しいタブで開きます)
  • レビューとお客様の声
  • お問い合わせ
  • Jetpack について
  • プレス
言語を選択 日本語
  • English
  • Deutsch
  • Español
  • Français
  • 日本語

© 2026 Automattic Inc. 無断転載を禁じます。

  • 利用規約↗ (新しいタブで開きます)
  • プライバシーポリシー↗ (新しいタブで開きます)
  • GDPR

によって心を込めて制作されています。

App Storeからダウンロード Google Playで入手
コメントを読み込み中…
  • リブログ
  • 定期購入 開始日
    Jetpack
    53,354人の購読者に加わりましょう

    WordPress.com のアカウントをお持ちですか ? 今すぐログインしてください。

  • Jetpack
    短縮リンクをコピーReader で投稿を表示
    購読管理登録ログイン
    このコンテンツを報告
    このバーを折りたたむ
%d