Add the Google Tag Manager code without plugins in WordPress... open

Add the Google Tag Manager code without plugins in WordPress. Code example

Approved. Code works!
This is exactly the working code that is verified by the moderator or site administrators

After we receive our code. We remind you, there should be 2 parts – 1 must be placed in the head and the other after the opening bodytag.

Well, let’s start. Let’s go to the admin panel of our site and open the function.php file of our active theme. Add to this file:

add_action('wp_head', 'lube_header');

function lube_header()
{

?>

    <!-- Google Tag Manager -->
    <script>
        (function(w, d, s, l, i) {
            w[l] = w[l] || [];
            w[l].push({
                'gtm.start': new Date().getTime(),
                event: 'gtm.js'
            });
            var f = d.getElementsByTagName(s)[0],
                j = d.createElement(s),
                dl = l != 'dataLayer' ? '&l=' + l : '';
            j.async = true;
            j.src =
                'https://www.googletagmanager.com/gtm.js?id=' + i + dl;
            f.parentNode.insertBefore(j, f);
        })(window, document, 'script', 'dataLayer', 'GTM-KTT1111');
    </script>
    <!-- End Google Tag Manager -->

<?php
};
add_action('wp_body_open', 'lube_body_top');

function lube_body_top()
{
?>

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

<?php
};
0

More

Leave a Reply

Your email address will not be published. Required fields are marked *

How many?: 22 + 22

lil-code© | 2022 - 2024
Go Top
Authorization
*
*
Registration
*
*
*
*
Password generation