Before you ask please READ THIS

Google analytics, tag manager

in Rife Posts: 45
Hi Air,

Hope you are ok, i can see you have been dealing with some medical issues.

I have a few questions about SEO on the Rife theme, i have been reading about and have been told that the best way to add the google code, both the analytics and google tag manager is to add it to the header.php file.

1) Do i add it in the child theme or the main theme ?

2) some themes have a special place in admin to add the code, does Rife have it or do i have to do it directly in the header.php file ?

3) will this affect when i make any updates to the theme or wordpress ?

Many thanks

Jorge



Comments

  • AirAir
    edited January 2018 Posts: 10,970
    Hi Jorge.

    Thanks for your interest, I am fine & will be back fully in next week :-)

    In header.php there is special comment that we added to explain how to do it best way.
    Anyway on our site we do it by wordpress action added in child theme. It looks like that:
    // GOOGLE TAG MANAGER 
    add_action('apollo13framework_head_start', function(){
    	echo <<<SCRIPT
    
    <!-- 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','XXX-YYYYYY');</script>
    <!-- End Google Tag Manager -->
    
    SCRIPT;
    });
    add it to functions.php in child theme

    With kind regards.
    Post edited by Air on
  • so yo saying not to add it to the rife-child header.php file but to the rife-child functions.php file ? i'm so sorry can you please be a bit more specific ?
  • AirAir
    edited January 2018 Posts: 10,970
    Sorry, I am afraid I didn't give you full code yesterday.

    However if you will view header.php in main theme you will see comments explaining how to do it best way with WordPress actions.

    You can do it either way. If you don't feel comfortable then add it in header.php. WordPress actions & filters are best way to do it safely.

    Like I said add this code in functions.php in child theme, just set there your code. For tag manger.

    Look at screen shot from our site:

    image

    Hope that will help.

    With kind regards.
    Post edited by Air on
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!