Updated on May 16, 2019

Looking to add Google Tag Manager code in your Oxygen-powered WordPress site?

Just add the following Snippet after installing and activating Code Snippets plugin:

add_action( 'wp_head', 'sk_google_tag_manager1', 1 );
 * Adds Google Tag Manager code in <head> below the <title>.
function sk_google_tag_manager1() { ?>

    <!-- Google Tag Manager -->
    new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
    <!-- End Google Tag Manager -->

<?php }

add_action( 'ct_before_builder', 'sk_google_tag_manager2' );
 * Adds Google Tag Manager code immediately after the opening <body> tag.
function sk_google_tag_manager2() { ?>

    <!-- Google Tag Manager (noscript) -->
    <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXXX"
    height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
    <!-- End Google Tag Manager (noscript) -->

<?php }

Replace the code inside the above functions with the snippets provided by Google in the Tag Manager interface or replace GTM-XXXXXX with your container ID.

Set the snippet to load on the frontend.

Reference: wp-content/plugins/oxygen/component-framework/oxygen-main-template.php.

Need help implementing a tutorial in your site or want to hire me for custom work?


Find the article helpful and wish to donate?

linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram
%d bloggers like this: