Head and body injections

Hello I need to put a google tag manager code in my site. I now how to do this with a plug-inn, but is there a way to do this without a plug-inn? It’s just a few lines for the head and the body

Thanks

Hi there,

You can achieve this by adding the code in the functions.php of the child theme:

/* Describe what the code snippet does so you can remember later on */
add_action('wp_head', 'your_header_function_name');
function your_header_function_name(){
?>
    PASTE HEADER CODE HERE
<?php
};

/* Describe what the code snippet does so you can remember later on */
add_action('wp_footer', 'your_footer_function_name');
function your_footer_function_name(){
?>
    PASTE FOOTER CODE HERE
<?php
};

Please make sure to change the function names for the header and footer codes and they should be unique.

Hope this helps.

1 Like

Awesome! Thanks!!!

Sorry just to make sure that I understand the function name could be something like:

(‘wp_head’, ‘your_header_googlagmanager_name’);

Or do i misunderstand?

Hi @RPronk,

Thanks for writing in again!

Yes, the function format is right.

You can replace the your_header_googlagmanager_name with the name of your choice.
Similar for footer function.

Thanks

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.