Google Analytics and Sydney child

Hi,
i’m using the sydney child theme and i should add the tracking code in the site.
Now, when i go to the editor, there isn’t the header.php where i can put my code.
How can i copy the entire header.php from sydney original theme and drop it to the child one?
Thank you

Hello there,

Adding some extra script to the site header through the heade.php file isn’t a good practice to do. You should use wp_head hook instead. Create a new function in your child theme’s functions.php file and hook it to wp_head. For example:


function sydney_child_header_script() {
    ?>
        <script>
            // Google Analytics goes here
        </script>
    <?php
}
add_action('wp_head', 'sydney_child_header_script');

Checkout other examples along with its technical details about it here on this codex page.

Regards,
Kharis

Ok i’ve understood.
But, first of all, is it necessary to add in the header.php this script:

<?php
add_action(‘wp_head’, ‘your_function’);
?>

in order to hook my new function on functions.php with wp_head in the header.php?
Because, i’ve seen in my header.php (in the original theme) this only script:

<?php wp_head(); ?>

So, if i write the function you send me on functions.php, is it able to hook with this last script or i have to add the first one on header.php?
Thank you

Hello there,

Ideally functions should be written in the functions.php file. The wp_head() function call holds the wp_head hook.

Regards,
Kharis