Last active
May 5, 2021 03:54
-
-
Save sitebuilderone/a43cbad3c541e1a8512461696e0cd6da to your computer and use it in GitHub Desktop.
Add GTM to WP via Code Snippets/functions file
This file contains 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 | |
/** | |
* Adds Google Tag Manager (GTM) code in <head> | |
*/ | |
add_action( 'wp_head', 'sb_google_tag_manager',100 ); | |
function sb_google_tag_manager() { ?> | |
<!-- Google Tag Manager --> | |
<script>code here ...</script> | |
<!-- End Google Tag Manager --> | |
<?php } | |
/** | |
* Adds Google Tag Manager code immediately after the opening <body> tag. | |
*/ | |
add_action( 'ct_before_builder', 'sb_google_tag_manager_2' ); | |
function sb_google_tag_manager_2() { ?> | |
<!-- Google Tag Manager (noscript) --> | |
<noscript>code here ...</noscript> | |
<!-- End Google Tag Manager (noscript) --> | |
<?php } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment