Hi, we’ve been asked to add in code for Google Tag Manager to the head of each page - is there a way of adding in the Google Tag Manager code to functions.php without having to add it to every page separately?
Hope that makes sense!
Thanks!
Hi, we’ve been asked to add in code for Google Tag Manager to the head of each page - is there a way of adding in the Google Tag Manager code to functions.php without having to add it to every page separately?
Hope that makes sense!
Thanks!
Hi, that’s great, thanks!
You are most welcome!
Hi, sorry, but have you got the script for the tag to go into the body of each page too please - I haven’t done that before and I’ve had a look on the forum and there’s a couple of different posts so I don’t know which one to use!
Thanks!
Hello @core365,
To add the Google tag Manager code in the child theme’s functions.php, you can use this code:
add_action('wp_head', 'add_gtm_code');
function add_gtm_code() {
?>
PASTE GOOGLE TAG MANAGER CODE HERE
<?php
}
And if you also need to add a tag code in the body, you can also use this:
add_action('x_after_body_begin', 'add_tag_code');
function add_tag_code() {
?>
PASTE TAG Code CODE HERE
<?php
}
Please let us know how it goes.
Hi, that’s great, thank you it’s much appreciated!
Cheers!
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.