Created
September 8, 2015 08:20
-
-
Save benhuson/3cd0d6c76a9b50a1bfb6 to your computer and use it in GitHub Desktop.
Google Tag Manager Patch - Only output tag once. https://wordpress.org/plugins/google-tag-manager/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: trunk/google-tag-manager.php | |
=================================================================== | |
--- trunk/google-tag-manager.php (revision 1182053) | |
+++ trunk/google-tag-manager.php (working copy) | |
@@ -11,6 +11,8 @@ | |
class google_tag_manager { | |
+ public static $output_once = false; | |
+ | |
public static function go() { | |
add_filter( 'admin_init', array( __CLASS__, 'register_fields' ) ); | |
add_action( 'wp_footer', array( __CLASS__, 'print_tag' ) ); | |
@@ -28,7 +30,7 @@ | |
<?php | |
} | |
public static function print_tag() { | |
- if( ! $id = get_option( 'google_tag_manager_id', '' ) ) return; | |
+ if( self::$output_once || ! $id = get_option( 'google_tag_manager_id', '' ) ) return; | |
?> | |
<!-- Google Tag Manager --> | |
<noscript><iframe src="//www.googletagmanager.com/ns.html?id=<?php echo $id; ?>" | |
@@ -40,6 +42,7 @@ | |
})(window,document,'script','dataLayer','<?php echo $id; ?>');</script> | |
<!-- End Google Tag Manager --> | |
<?php | |
+ self::$output_once = true; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment