gtm4wp_get_the_gtm_tag

The Google Tag Manager for WordPress gtm4wp get the gtm tag function.

Description

gtm4wp_get_the_gtm_tag(); 

Usage

  1. if ( !function_exists( 'gtm4wp_get_the_gtm_tag' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'google-tag-manager-for-wordpress/public/frontend.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = gtm4wp_get_the_gtm_tag(); 
  7.  

Defined (1)

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

/public/frontend.php  
  1. function gtm4wp_get_the_gtm_tag() { 
  2. global $gtm4wp_options, $gtm4wp_datalayer_name, $gtm4wp_container_code_written; 
  3.  
  4. $_gtm_tag = ' 
  5. <!-- Google Tag Manager (noscript) -->'; 
  6.  
  7. if ( GTM4WP_PLACEMENT_OFF == $gtm4wp_options[ GTM4WP_OPTION_GTM_PLACEMENT ] ) { 
  8. $gtm4wp_container_code_written = true; 
  9.  
  10. if ( ( $gtm4wp_options[ GTM4WP_OPTION_GTM_CODE ] != "" ) && ( ! $gtm4wp_container_code_written ) ) { 
  11. $_gtm_codes = explode( ", ", str_replace( array(";", " "), array(", ", ""), $gtm4wp_options[ GTM4WP_OPTION_GTM_CODE ] ) ); 
  12.  
  13. foreach( $_gtm_codes as $one_gtm_code ) { 
  14. $_gtm_tag .= ' 
  15. <noscript><iframe src="//www.googletagmanager.com/ns.html?id=' . $one_gtm_code . '" 
  16. height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>'; 
  17.  
  18. $_gtm_tag .= ' 
  19. <!-- End Google Tag Manager (noscript) -->'; 
  20.  
  21. $_gtm_tag = apply_filters( GTM4WP_WPFILTER_GETTHEGTMTAG, $_gtm_tag ); 
  22. $gtm4wp_container_code_written = true; 
  23.  
  24. return $_gtm_tag;