X Theme - Google Tag Manager

Good afternoon Themeco,

First of all, I really love the X theme. I’d like to add the codes for Google Tag Manager. I have to add one code after the tag, one after the tag. I searched the forum, but I couldn’t find a solution, since I can’t find _header.php in wp-content/themes/x/framework/views/global/ and add it to my child theme.

I hope you can help me out. Thanks in advance!

Kind regards,

Don

Hi Don,

Please add the following code under functions.php file locates in your child theme:

add_action( 'wp_head', 'add_head_script', 999 );
function add_head_script(){
	?>
	<!-- Your scripts will go here -->
	<?php
}

Thanks for this but where do we add the ‘body’ tag?

GTM requires that a script be added to the head & the body.

C

I would recommend simply using Duracelltomi’s GTM plugin. Very lightweight, adds a couple good options, and is easy to implement.

Hi There,

Since Google recommend the <noscript> code goes as close as possible in the <body> tag, you need to do this with a custom template.

To do this first navigate to this directory:
x/framework/legacy/cranium/headers/views/global/ and copy the file _header.php

Then on your child theme navigate to this directory:
x-child/framework/legacy/cranium/headers/views/global/
If this directory does not exist, create it. Then there paste the _header.php file that you just copied.

Then open and edit the copied _header.php file, put your Google Tag Manager (noscript) code just below the line:

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

Ofcourse you can also use the plugin suggested by @BEAUTYSHOTS

Cheers :slight_smile:

Hi, do you use this plugin? What installation option fron the 4 proposed best wotk with this theme? If custom where do you inplement the snipet? Thanks

Hi there,

As instructed above, you will have to add it in your _header.php, the folder path is provided above. Then you’ll use any FTP client software or your hosting’s file manager to do that. Some hosting file manager has it’s own code editor, it’s much better :slight_smile:

I’m not sure about the plugin since it’s not from us.

Thanks!

Does modifying the _header.php work on a Pro theme base? Because I tried adding the GTM just after the opening body tag on a Pro site and it seems to be ignoring the changes.

Hi,

Yes, it should work.

Where did you add your code in your main PRO theme or in your child theme?

Make sure to add it in your child theme in wp-content/themes/pro-child/framework/legacy/cranium/headers/views/global/_header.php

The file needs to be in correct path or else the theme will ignore it.

Thanks

1 Like

OMG - this is exactly what I was looking for!

Hi,

Glad to know this helped.

Have a nice day! :slight_smile: