Created
January 4, 2021 15:39
-
-
Save mbrughi/a4eb77c3982c1080dcb8d5dcfbf6c1b9 to your computer and use it in GitHub Desktop.
Wordpress: Add Google Tag Manager Code right after <body> open tag by wp_body_open hook.
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
/* | |
* Insert Google Tag Manager right after body open tag | |
* @link https://marcobrughi.com | |
* | |
* @author Marco Brughi <[email protected]> | |
* | |
* NB: Change Code with your's | |
*/ | |
function mb_add_after_body_code() { | |
echo '<!-- Google Tag Manager (noscript) --> | |
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXX" | |
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript> | |
<!-- End Google Tag Manager (noscript) --> | |
'; | |
} | |
add_action( 'wp_body_open', 'mb_add_after_body_code' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment