Dynamically change the Google Tag Manager Container ID (Pro Feature)

Need help with this?
Purchase All in One SEO Pack Pro to get dedicated support from us.

Buy Now

The All in One SEO Pack aioseop_gtm_container_id filter hook.

Description

$container_id = apply_filters( 'aioseop_gtm_container_id', $aioseop_options['aiosp_gtm_container_id'] );

This filter can be used to dynamically change the Google Tag Manager Container ID based on any given conditions and is useful when you do not want to output the same container ID on every single page.


Parameters (1)

0. (string)
the Google Tag Manager Container ID.

Usage

The code example below can be used to change the Google Tag Manager Container ID for Date Archive pages:

add_filter( 'aioseop_gtm_container_id', 'change_gtm_container_id' );

function change_gtm_container_id( $container_id) {
        if( is_date() ) {
           $container_id = 'GTM-ABC123';
        }
        return $container_id;
}

Defined (1)

The filter is defined in the following location(s).

pro/aioseop_google_tag_manager.php

For instructions on how to use this code, please refer to our FAQ here.

  • Was this helpful ?
  • YesNo
[i]
[i]
Skip to toolbar