skip to Main Content

I tried to add the Google Tag Manager to the header.php of my WordPress site. I used child theme "Hello Elementor", template from Envato with Elementor’s builder for placing and editing content to website.

I placed first code in header.php inside <head></head> and second after <body <?php body_class(); ?>> but didn’t have any result. After checking source code on page, there doesn’t show codes. Tag Assistance by Google no tags found.

Can somebody helps me to solve this issue, please)

2

Answers


  1. Chosen as BEST ANSWER

    I found solution in this tutorial video: https://www.youtube.com/watch?v=6iqeqmlKLyQ

    For my case I used functions.php in which had placed specific code blocks:

    add_action( 'wp_head', 'my_javascript_code' );
    
    function my_javascript_code() { 
        // YOUR JAVASCRIPT CODE GOES BELOW 
        ?>
           <script type="text/javascript">.....</script>
        <?php
    }
    

    and

    add_action( 'wp_body_open', 'my_javascript_code' );
    
    function my_javascript_code() { 
        // YOUR JAVASCRIPT CODE GOES BELOW 
        ?>
           <script type="text/javascript">.....</script>
        <?php
    }
    

  2. First of all, why not use this all-in-one plugin by Google: https://wordpress.org/plugins/google-site-kit/

    As for your question, I see three options here:

    1. What code did you add? Did you paste code from GTM or did you use a php snippet? I’m asking because most php implementations will not insert the code when a user is logged-in to WordPress. Try looking from another browser, or in incognito mode.

    2. Caching – did you make sure to clear it?

    3. Did you change the correct file? Try adding a comment somewhere inside your header.php file and see if it shows up on your site.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search