• Resolved momadvisorblog

    (@momadvisorblog)


    Hi Shea,

    I need to add the following snippet and paste it immediately after the opening <body> tag on every page of my website, to install Google Tag Manager.

    <!– Google Tag Manager (noscript) –>
    <noscript><iframe src=”https://www.googletagmanager.com/ns.html?id=GTM-XXXX&#8221;
    height=”0″ width=”0″ style=”display:none;visibility:hidden”></iframe></noscript>
    <!– End Google Tag Manager (noscript) –>

    Could you help me with the right snippet please? I placed it in the footer, and it´s not working 🙂

    Thank you!!!

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • go to header.php and you will find <head> & <body> tag

    Plugin Author Shea Bunge

    (@bungeshea)

    Hi @momadvisorblog,

    Unfortunately, there isn’t a standard way in WordPress for adding code just after the <body> tag. The means for doing so really depends on what theme you are using. Some themes will provide a filter that you can hook to similar to wp_head; for others you will need to add a line of code yourself.

    But @sanwal is correct that to find out, you should take a look at your theme’s header.php file.

    Thread Starter momadvisorblog

    (@momadvisorblog)

    Thank you!

    This is what I found in the header.php file.

    <!DOCTYPE html>
    <html <?php language_attributes(); ?> class=”no-js”>
    <head>
    <meta charset=”<?php bloginfo( ‘charset’ ); ?>”>
    <meta name=”viewport” content=”width=device-width”>
    <link rel=”profile” href=”http://gmpg.org/xfn/11″&gt;
    <link rel=”pingback” href=”<?php bloginfo( ‘pingback_url’ ); ?>”>
    <?php wp_head(); ?>
    </head>

    <body <?php body_class(); ?>>
    <div id=”ds-container” >
    <?php do_action(‘dt_before_header’); ?>
    <?php
    $enable_header_top = esc_attr(get_theme_mod(‘dt_enable_header_top’, DT_ENABLE_HEADER_TOP));
    if ($enable_header_top == ‘1’) {
    $extra_class = ‘dt-header-top-enabled’;
    } else {
    $extra_class = ”;
    }
    ?>

    I added this but there´s an error:

    add_action( ‘body_class’, function () { ?>
    <!– Google Tag Manager (noscript) –> etc

    I think it´s adding it before instead of after the <body> tag.

    And now I´m getting this line:
    class=”home-page bp-legacy geodir_advance_search geodir_custom_posts geodir-page sd-common sd sd-homepage wpb-js-composer js-comp-ver-5.1 vc_responsive elementor-default no-js gd-map-auto”>

    Help please 🙂

    Plugin Author Shea Bunge

    (@bungeshea)

    Hi @momadvisorblog,

    You shouldn’t really be using the body_class filter hook for this purpose.

    Instead, I’d recommend using the dt_before_header action:

    add_action( 'dt_before_header', function () { ?>
    
    <!-- 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) -->
    
    <?php } );
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Google Tag Manager’ is closed to new replies.