Hello,
I’ve a question about adding some code to the header.php in the ChidTheme.
For a site i need to add the code for the Google Tag Manger, you see this in the private area. The question is, do i need to copy the hole header.php for this and add the code there? Or is it possible just to copy a part of it in the childtheme?
Because this provokes problems when the header file is update in the original theme, not? I there a solution for that?
Thanks for helping me out!
Best Regards
Hey Tim,
Instead, please add following code to Functions.php file of your child theme
function my_custom_code_head(){
?>
//Your code goes here
<?php
}
add_action('wp_head', 'my_custom_code_head');
Best regards,
Yigit
Hi,
Thanks you for the response.
Do you mean I have to put the hole code in at the position: “//Your code goes here” ?
Because the code of the Tag-Manager consist of two parts. One for in the <head> and the other after the <body> tag.
Thanks for helping out!
Regards,
Hi,
The code you need after the body tag could be inserted using this:
function my_custom_code_footer(){ ?>
//YOUR CODE HERE
<?php }
add_action('wp_footer', 'my_custom_code_footer');
Best regards,
Rikard
Thank you! For helping!