Support » Theme: Singl » On what page do I add Google Tag Manager code?

  • Hey there!
    On what page for Singl and on what line number do I add the code for Google Tag manager?
    site: FU5K4.COM
    Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator Kathryn

    (@zoonini)

    Automattic Happiness Engineer

    Are you referring to the Google Tag Manager plugin here?

    https://wordpress.org/plugins/google-tag-manager/

    I’m not familiar with that plugin, but it doesn’t look like you need to make any theme changes to use it.

    On the other hand, since it hasn’t been updated in over 2 years, you may not work with current themes or versions of WordPress.

    Thread Starter getnoizefu5k4

    (@getnoizefu5k4)

    Hey Kathryn,

    Thank you for your input. Like you mentioned there are no reliable plugins that are either up to date or that insert the code the way Google wants to:

    “Place it immediately after the opening <body> tag.”

    I have read since I am using a Theme, correct me if I’m wrong, to insert the Google Tag Manager code within Functions.php file that belongs to Singl or whatever theme you are using.

    That didn’t work at all, nobody should try it as it caused a serious error I could only fix by using my server and replacing the file manually, but I’ll add it below as an example:

    // Add Google Tag Manager Code
    // =============================================================================
    function add_google_tag_manager_code(){
    ?>

    <!– Insert Google Tage Code Here –>

    <!– Insert Google Tage Code Here –>

    <?php
    }
    add_action( ‘x_before_site_begin’, ‘add_google_tag_manager_code’ );

    // End Add Google Tag Manager Code
    // =============================================================================

    I’m sure there’s a way.

    Thanks again!

    Moderator Kathryn

    (@zoonini)

    Automattic Happiness Engineer

    Thanks for the details!

    You should never modify your theme files directly, especially the functions file, as you learned the hard way. I’m glad you were able to recover from that. πŸ™‚

    The opening <body> tag in Singl is in the header.php file, on line 49:

    <body <?php body_class(); ?>>

    I’d suggest you first create a child theme, so your changes won’t be overwritten every time you update the theme to the latest version.

    Here are some guides in case you haven’t made one before:

    http://codex.wordpress.org/Child_Themes
    http://op111.net/53/
    http://vimeo.com/39023468

    Once your child theme is set up, make a copy of header.php from the parent and place it in your child theme folder.

    Then add your Google Tag Manager code below the opening body tag. Be sure to put it between opening and closing PHP tags, which look like this:

    <?php
    
    ?>

    Ideally, you would also make this sort of change first on a local install of your site, or a test/development server before making it live.

    Moderator Kathryn

    (@zoonini)

    Automattic Happiness Engineer

    Actually on re-reading your instructions you have conflicting information.

    In one place, you say to add the code after the opening body tag, but the code itself is a function which looks like it should go into functions.php.

    I would double-check the instructions on how to do this correctly directly from the source before making any changes.

    If it’s indeed meant to go in your functions.php file, you would create a functions.php file for your child theme and place the function there. In functions.php in WordPress you only add an opening <?php tag, not a closing one, then add the Google function.

    Again, I strongly suggest doing this locally or on a test site first to be sure you don’t take your site down again. πŸ™‚

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘On what page do I add Google Tag Manager code?’ is closed to new replies.