Skip to content
Facebook Twitter Github RSS
Google Tag Manager for WordPress
  • Home
  • FeaturesExpand
    • Basic features of GTM4WP

      You can use many post or page attribute in you Google Tag Manager setup even for custom post types and taxonomies.

      Basic data

      Page / post attributes

      Site search

      User data

      Multisite data

      3rd party data

      Browser attributes

      Device attributes

      Operating system attributes

      Weather conditions

  • SetupExpand
    • Setup advanced GTM4WP features

      Integrate your measurement with WooCommerce, setup Google Analytics 4, Google Ads remarketing or conversion tracking maximizing capabilities.

      WooCommerce related

      Google Analytics 4

      Google Ads – Dynamic Remarketing

      Google Ads – Conversion tracking

      Google Ads – Enhanced Conversions

      Other setup articles

      Exclude WordPress admins

      Embedded media players

  • DevelopersExpand
    • Information for developers and WP managers

      There are several tools in GTM4WP to support your special needs and to adjust plugin behavior to your website or WooCommerce shop.

      Do you want to contribute with a bugfix or a new feature? Visit the GTM4WP’s GitHub page!

      For Developers

      Actions and filters

      WP themes + Proper ecommerce tracking

      For WP managers

      Setup GTM Environments

      Hard code GTM parameters

  • Blog
  • GDPR
Download
Google Tag Manager for WordPress
Home / GTM4WP For Developers / Hard code Google Tag Manager parameters in wp-config.php

Hard code Google Tag Manager parameters in wp-config.php

You can set a fixed Google Tag Manager container ID and environment options in wp-config.php using PHP contants. This gives you better workflows when dealing with different environments to develop and test updated version of the whole site. Setting GTM container parameters like this will change the corresponding lines on the plugin options page to a disabled, read only state. Even site administrator will not be able to override the container code on the options page. To change or remove the hard coded values, you need to access your wp-config.php file and edit the corresponding lines.

Use the following PHP constants:

  • GTM4WP_HARDCODED_GTM_ID
  • GTM4WP_HARDCODED_GTM_ENV_PREVIEW
  • GTM4WP_HARDCODED_GTM_ENV_AUTH

GTM4WP_HARDCODED_GTM_ID

This has to be one or more valid Google Tag Manager IDs (GTM-XXXXX). If you want to load multiple container, separate the list with commas. You must not use spaces around commas when listing the container codes.

GTM4WP_HARDCODED_GTM_ENV_PREVIEW

This must include the value of the gtm_preview parameter from the container code of your Google Tag Manager environment. If you use this option, only provide one container ID in plugin options or in the GTM4WP_HARDCODED_GTM_ID constant. Currently, only loading of one container is supported when using environments. If you set this constant, also set GTM4WP_HARDCODED_GTM_ENV_AUTH in order for the environment to properly load.

To learn more about how to get this parameter from the container code, please check the GTM environment setup guide.

GTM4WP_HARDCODED_GTM_ENV_AUTH

This must include the value of the gtm_auth parameter from the container code of your Google Tag Manager environment. If you use this option, only provide one container ID in plugin options or in the GTM4WP_HARDCODED_GTM_ID constant. Currently, only loading of one container is supported when using environments. If you set this constant, also set GTM4WP_HARDCODED_GTM_ENV_PREVIEW in order for the environment to properly load.

To learn more about how to get this parameter from the container code, please check the GTM environment setup guide.

© 2025 Google Tag Manager for WordPress - Privacy policy

  • WordPress.org plugin page
  • Plugin support
  • Plugin reviews
  • Home
  • Features
    • Basic features of GTM4WP

      You can use many post or page attribute in you Google Tag Manager setup even for custom post types and taxonomies.

      Basic data

      Page / post attributes

      Site search

      User data

      Multisite data

      3rd party data

      Browser attributes

      Device attributes

      Operating system attributes

      Weather conditions

  • Setup
    • Setup advanced GTM4WP features

      Integrate your measurement with WooCommerce, setup Google Analytics 4, Google Ads remarketing or conversion tracking maximizing capabilities.

      WooCommerce related

      Google Analytics 4

      Google Ads – Dynamic Remarketing

      Google Ads – Conversion tracking

      Google Ads – Enhanced Conversions

      Other setup articles

      Exclude WordPress admins

      Embedded media players

  • Developers
    • Information for developers and WP managers

      There are several tools in GTM4WP to support your special needs and to adjust plugin behavior to your website or WooCommerce shop.

      Do you want to contribute with a bugfix or a new feature? Visit the GTM4WP’s GitHub page!

      For Developers

      Actions and filters

      WP themes + Proper ecommerce tracking

      For WP managers

      Setup GTM Environments

      Hard code GTM parameters

  • Blog
  • GDPR
Search