Customising the header.php file of a child theme
In a previous article I covered creating a child theme. Child themes are the solution the WordPress team came up with to let theme authors and users work in parallel without getting in each other's way.

In a previous article I covered creating a child theme.
Child themes are the solution the WordPress team came up with to let theme authors and theme users work in parallel without interfering with each other. Users can customise the child theme while authors can ship updates with peace of mind, knowing they won't destroy the work of whoever customises their theme.
So you can customise a theme while its author keeps updating it, which keeps installations secure.
Contents
Editing the theme
In my case I added a tag to the head of the theme's HTML.
The tag in question is the script that enables Google Tag Manager.
With Google Tag Manager you can add, enable and manage scripts such as Analytics or the Facebook Pixel without touching the site's code.
How do you edit the code of a child theme?
Here is what I did:
// I copied the header.php file from
/wp-content/themes/twentynineteen/
// to the folder
/wp-content/themes/twentynineteen-childAnd this is what the header.php file looks like after my addition:
<?php
/**
* The header for our theme
*
* This is the template that displays all of the <head> section and everything up until <div id="content">
*
* @link https://developer.wordpress.org/themes/basics/template-files/#template-partials
*
* @package WordPress
* @subpackage Twenty_Nineteen
* @since 1.0.0
*/
?><!doctype html>
<html <?php language_attributes(); ?>>
<head>
<!-- MISSING CODE -->
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','YOUR-CODE');</script>
<!-- End Google Tag Manager -->
</head>
<body <?php body_class(); ?>>
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=YOUR-CODE"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->
<?php
wp_body_open();
?>
<!-- MISSING CODE -->As you can see, making changes on top of a parent theme is quick and simple.
What's more, this method also makes your installation more secure, because you can update the theme without losing the work you did on the child theme.