Last active
January 20, 2021 12:07
-
-
Save hegemanjr/0bcc329e4789bffd9d5c5dd81bed2c5b to your computer and use it in GitHub Desktop.
Add Google Tag Manager GTM without plugin
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
<?php | |
// Add Google Tag code which is supposed to be placed in the <head>. | |
function soes_inject_gtm_head() { | |
// Add GTM head tag | |
?> | |
<!-- Google Tag Manager --> | |
<!-- End Google Tag Manager --> | |
<?php | |
} | |
// Use wp_head to call our function to inject the tag in the <head> | |
add_action('wp_head', 'soes_inject_gtm_head'); | |
// Add Google Tag code which is supposed to be placed after opening <body> tag. | |
function soes_inject_gtm_body() { | |
// Add GTM body tag | |
?> | |
<!-- Google Tag Manager (noscript) --> | |
<!-- End Google Tag Manager (noscript) --> | |
<?php | |
} | |
// Use wp_body_open to call our function to inject the tag in the <body> | |
add_action( 'wp_body_open', 'soes_inject_gtm_body' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment