Skip to content

Instantly share code, notes, and snippets.

@mbrughi
Created January 4, 2021 15:39
Show Gist options
  • Save mbrughi/a4eb77c3982c1080dcb8d5dcfbf6c1b9 to your computer and use it in GitHub Desktop.
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.
/*
* 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