Share this post

How to Copy Header.php File From Parent Theme to Child Theme

How to copy Header.php from parent theme to child theme

There are times when you as a website developer may want to introduce a code snippet in your WordPress theme and wondering how to go about doing that. Some snippets of code require you to add it to your header.php file and you find yourself scrambling for a solution that is efficient and can stand the test of time. We’re pretty sure that someone on the internet is yelling to add that snippet in the child theme and you nod your head meekly, agreeing with the advice…but still completely lost inside. “How do you copy header.php from the parent to the child theme?” - you shake your head in anguish - still searching for an answer and a way out.

In this post we’ll show how you can easily copy the header.php file from the parent theme to the child theme in WordPress. But before we get to that, let’s ask ourselves why we need to go through the exercise and the extra effort?

Historically speaking, in WordPress there was just one type of theme that included all the functionality required to display the content of your website. This theme is known as the parent theme. You could make any number of changes to this parent theme and the website would ultimately reflect those changes on the front-end for you. However, if you wanted to update the theme at any time (which you should for a variety of reasons), you’d stand to lose all the past changes you made to that theme. All the efforts you took to add customized styling to your parent theme will be gone as and when you update it. Which sucks, honestly.

So WordPress came up with an ingenious idea of a child theme that will inherit all the style, functionality and features of the parent theme. This parent-child relationship made it much easier for WordPress developers to add custom styling to a website without the fear of losing them. The parent theme is therefore left largely untouched as most of the customization and modification is done in the child theme. You therefore have the ability to update the parent theme without any risk of losing your added custom styles in the child theme.

Many of the modern day WordPress themes now come along with a child theme…or at least, they make it easy to create one. At WP Adventure, we work with Astra – one of the most popular WordPress themes there is on the market and it makes it incredibly easy to create a child theme.

Let’s see how we can copy any file from the parent theme to its child theme. For the sake of this post, we’ll take a step by step approach to copy the header.php file from the parent to the child theme.

Note 1: It is not necessary to copy all the files from the parent theme to the child theme. For example, you can copy only the header.php from the parent theme to the child theme, if you wish to add code for Google analytics or Google tag manager (for example). Thus, these codes will remain and function even if you update your parent theme.

Note 2: We assume that you have already created a child theme before proceeding further. Please remember the name of the child theme you’ve created as we’ll require it during the process.

Before proceeding with the exact steps, please ensure that you have uploaded your child theme and activated it in your WordPress. As you can see below, we have our child theme – WP Adventure – activated:

Child theme activated

How to copy header.php from parent theme to child theme.

Since the vast majority of people use a cPanel based host, we will be using that for our demonstration purposes here.

1) Login to your cPanel account and click on File Manager

File manager in cPanel hosting

2) Make sure that you are in the root directory for your website. For this demo, we have our website in the public.html folder so we’ll open that.

Public-html folder in cPanel

3) Click on the wp-content folder and open it.

WP-content folder in cPanel

4) Click on the Themes folder and open it.

Themes folder in cPanel

5) You’ll now see all the themes installed on your WordPress. We have 2 themes as seen below – the parent theme (Astra) and the child theme (WP Adventure)

2 themes in themes folder in cPanel

6) If you want to see which files are inherited by the child theme, simply click on the child theme and they’ll get displayed. As you can see below, we have only the functions.php and style.css files in the child theme.

2 files in child theme

7) Now go back one step and click the parent theme folder to open it.

Click on parent theme folder in cPanel

8) You’ll see the header.php file in it – which we want to copy over to the child theme.

Click on header.php file in parent theme

9) So, right click header.php and click Copy.

Copy header.php file

10) You will now see a popup showing the location of the file in the parent theme folder (i.e. Astra in this case)

Location of header.php file in parent theme folder

11) Simply change the folder name to the child theme folder and click Copy files. In our case here, the child theme folder name is child-theme-wpadventure, so we’ve changed it accordingly.

Change location of header.php file to copy in child theme folder

12) If you head back to the child theme folder, you should now see the header.php file copied over successfully in that location.

Header.php file copied in child theme folder

13) Now, go back to your WordPress backend, click Theme Editor under Appearance and select your child theme, you should now see the header.php file displayed here, as shown:

Header.php file copied as seen in WordPress theme editor

You can now open the header.php file and add the appropriate codes here as you wish.

That's about it. If you've followed all the steps outlined above, you would have successfully copied the header.php file from the parent theme to the child theme in WordPress.

This works not only for the header.php file but for any file that you'd like to copy over from the parent to the child theme. Hope this post helped you a bit!

We're all on an adventure!

2nd Floor, Building No. 150, Zakaria Masjid Street, Mumbai - 400 009, India.

Web design

Web development

WordPress development

SEO services

Ecommerce SEO services

Local SEO services

Social media marketing

Digital marketing

Internet marketing

Pay per click (PPC)

Content writing

Mobile app development

Website SEO Audit

Blog

About Us

Contact

Refer and Earn

Privacy Policy

Scroll to Top