Using a Child Theme to Customise WordPress Safely

Woman coding a website

Many WordPress sites start with a theme someone else built. Sooner or later you want to change something in it. Maybe the header needs a different layout, or a template needs an extra section. The quickest fix is to open the theme files and edit them, but that edit has a short life.

The WordPress Theme Handbook describes child themes as extensions of a parent theme. They let you change a theme without touching the parent’s own files. This post explains how they work, which files you need and the mistakes worth avoiding. It covers classic themes and the newer block themes.

Why edits to a parent theme disappear

A theme from the directory or a premium seller gets updates. Those updates replace the theme’s files with fresh copies. Any change you made directly inside those files goes with them. The Theme Handbook warns that custom code placed in the parent will be lost on the next update.

Without a child theme, that leaves two poor choices. You can skip updates and keep your edits, or update and lose them. Skipping updates means missing fixes from the theme author. A child theme removes the need to pick between the two.

What a child theme actually is

A child theme is a separate theme folder that points at a parent. By default it inherits the parent’s design and functionality. You then add only the changes you want on top. The handbook lists the benefits as keeping your customisations separate, making them portable and writing only the code you need.

If you are still getting your head around how themes control layout, our guide on how WordPress themes work covers the basics. A child theme follows the same rules. It simply hands most of the work back to the parent. Your own folder stays small and easy to read.

The one file every child theme needs

According to the handbook, style.css is the only file that is strictly required. Its header comment must include two fields, Theme Name and Template. Theme Name is the label you see in the dashboard. Template tells WordPress which parent to use.

The Template value must exactly match the folder name of the parent theme inside wp-content/themes. It is the folder name that counts, not the display name. For the Twenty Twenty-Four default theme, the handbook gives the folder name as twentytwentyfour. A small typo here breaks the link between the two themes.

Loading the right stylesheets

Stylesheets are where many people get stuck. The handbook explains that some parent themes already load both their own stylesheet and the child’s. In that case you do not need to add anything. Other parents load no stylesheet at all, or only the stylesheet of the active theme.

In those cases you enqueue the styles yourself from the child theme’s functions.php file. The handbook hooks this to the wp_enqueue_scripts action. The only way to know which situation you are in is to check what the parent enqueues. For block themes the step is often optional, because they usually handle styling through theme.json instead.

How functions.php behaves in a child theme

This part is easy to get wrong. A child theme’s functions.php does not replace the parent’s version. Both files load, and the child’s file loads first. That makes it the right place for custom functions you want to keep through parent updates.

The handbook is firm about one mistake. Do not copy the parent’s functions.php code into the child. Because both files run, the same function names would be declared twice. The handbook says this will likely cause fatal errors.

Overriding templates, parts and patterns

To change a parent template, you add a file with the same name to the child theme. WordPress then uses the child’s copy instead of the parent’s. The same approach works for template parts and patterns. Patterns also need a matching registered Slug for the override to apply.

You are not limited to replacing what the parent provides. The handbook notes that a child theme can add new templates, parts and patterns too. This is handy when you want an extra page layout the parent never shipped. Plan these changes with the whole site in mind, and our notes on designing a WordPress website can help with that.

Block themes and theme.json layers

Block themes add another layer to think about. The handbook describes the order as the WordPress default theme.json, then the parent theme, then the child theme and finally user customisations. Each layer can adjust what came before it. Your child theme sits between the parent and anything saved in the editor.

User customisations are stored in the database rather than in theme files. The handbook says they can override theme.json, templates and patterns. So if a change in your child theme seems to do nothing, an edit saved through the editor may be sitting on top of it. Checking for saved customisations is a sensible first step when that happens.

Good habits for child theme code

A few habits from the handbook make child themes easier to live with. They mostly concern file paths and translations. None of them take long to set up. Here they are in short form.

  • Use get_theme_file_path() and get_theme_file_uri() when you reference included files and assets.
  • Give the child theme its own text domain for translations.
  • Load translations with load_child_theme_textdomain() rather than load_theme_textdomain().
  • Keep custom code in the child and never in the parent.

Keep the child theme lean as well. Every extra stylesheet and script is one more file for the browser to load. If page speed matters to you, see our tips to speed up your WordPress website. A tidy child theme is also easier to check when something goes wrong.

When a child theme is not the right tool

Child themes suit small and medium changes. For large changes, the handbook suggests forking the parent into a full theme of your own instead. At that point you maintain a separate theme, and updates from the original author no longer reach you. That is a bigger commitment, so weigh it up first.

There is another limit. The handbook says there is no standard way to make an installable grandchild theme. If you already run a child theme supplied by a theme seller, you cannot simply stack another one on top. Part of why WordPress themes are so popular is this kind of flexibility, but it does have edges.

Frequently asked questions

Do I need a child theme to change colours or fonts?

Not always. Many themes offer colour and font settings of their own. In block themes, the handbook notes that user customisations are stored in the database rather than in theme files. A child theme matters most when you edit theme files or add code.

Will a child theme slow down my site?

A basic child theme adds very little. It may load one extra small stylesheet. Any slowdown usually comes from what you add to it, such as heavy scripts. Keep it to the changes you actually need.

Can I add a child theme to a site that is already live?

Yes, but take a backup first. Activating the child theme changes the active theme, so check your menus, widgets and settings afterwards. Test on a staging copy if your host offers one. Then move your existing edits across before you update the parent.

What happens if the parent theme is deleted?

The child theme depends on the parent to work. The Template field points at the parent’s folder, so that folder must stay installed. Remove it and the child has nothing to inherit from. Keep both installed and keep the parent updated.

A child theme takes a little setup and saves a lot of rework later. Start with a correct header in style.css, check how the parent loads its styles and keep your custom code in the child. Then you can run parent updates without losing your changes.