How can I edit header.php?

Hello there,

trying to add google tag generator to my site and I need to add couple of codes to the header in the “Head” and in the “body” but when I go to: Editor - Theme Header - Can’t find anything there…

Any help would be appreciated. Thanks

Hi there,

If you want to add a code to the head section of the site, you do not have to edit the header.php.

You can just place this code to the functions.php file of the child theme:

add_action('wp_head', 'add_head_code');

function add_head_code() {
?>
    PASTE HEADER CODE HERE
<?php
}

Please place the code in the PASTE HEADER CODE HERE part.

Hope this helps.

1 Like

thanks Jade.

Can you be a bit more specific please? Can I just drop that line of code anywhere in that functions.php file?

I’ve attached 2 pics … one of them is what Google is asking me to do and the other one is the functions.php file, maybe you can tell easier where should I paste that line of code you mentioned above.

Hello @adrianonline,

Thanks for updating the thread.

Please make sure to replace or after PASTE HEADER CODE HERE and add the Google tag manager code. You can add the changes either at the start of function.php file or at the end.

Thanks.

Hello Jade, and to add the body part, what action may I use?

Hello There,

You may use this code:

add_action('wp_head', 'add_head_code');
function add_head_code() { ?>

  PASTE HEADER CODE for Google Tag Manager

<?php }

add_action('x_before_site_begin', 'add_additional_head_code');
function add_additional_head_code() { ?>

  PASTE BODY CODE for Google Tag Manager (no script)

<?php }

If you need anything else, please let us know.

1 Like

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