Skip to content

Child theme

A child theme is a small theme that takes its design and features from another theme, its parent, and holds only your changes to it. The parent can then be updated without those changes being lost.

By
WP Ministry
Published

In short

  • A child theme holds your changes to a theme, and the parent holds everything else. Both have to stay installed.
  • Changes made inside the parent theme's own files are lost when the parent is updated. Changes kept in the child are not.
  • You may not need one. A few CSS rules, and anything changed in the Site Editor on a block theme, are stored in the database.

A child theme is a theme that borrows everything from another theme, its parent, and adds or replaces only what you put in it. WordPress takes the design and the features from the parent and lays the child's files over them. Your changes sit in the child's folder, apart from the parent's code.

That matters because of updates. An update replaces a theme's files with the new version's, so code or CSS typed into the parent theme's own files is gone after its next update. What is in the child stays, and the parent can still be updated.

Where you meet it

  • On the Themes screen. Go to Appearance, then Themes. The child is the active theme, and the parent is installed beside it but not active. Open "Theme Details" on the child and it says "This is a child theme of", followed by the parent's name.
  • In the site's files. wp-content/themes/ holds a folder for each. The child's style.css opens with a header, and its Template: line names the parent's folder. That file is the only one a child theme must have. It may also hold a functions.php, which runs as well as the parent's and not in place of it, and copies of the parent's templates, each of which replaces the parent's file of the same name.
  • In instructions. A tutorial that says "add this to your child theme's functions.php" means this folder.

What goes wrong

Changes were made in the parent and an update removed them. Put them in a child theme before the next update. See how to create a child theme, and how to update safely so that you can go back if something was missed.

The parent was deleted because it looked unused. The child cannot work alone. The Themes screen lists it under "Broken Themes" with "The parent theme is missing." If the child was the active theme, the front of the site goes blank. When an administrator next opens the Themes screen, WordPress answers "The active theme is broken. Reverting to the default theme." and switches to a default theme. Install the parent again and activate the child.

Code pasted into the child's functions.php stops the site. One missing character is enough: see how to fix "Parse error: syntax error, unexpected". Copying a function out of the parent's functions.php fails too. Both files are loaded, so PHP meets the same function name twice.

A copied template falls behind. A template in the child replaces the parent's, so later fixes to that file in the parent do not reach your site. Copy only the templates you change.

How to look at yours

The Themes screen shows it, as above. With WP-CLI:

bash
wp theme list --fields=name,status,version

When a child theme is active, its row reads active and its parent's row reads parent.

Common questions

Do I need a child theme?

Only if you change the theme's code or templates, or keep a long stylesheet of your own. A few CSS rules belong in the "Additional CSS" box: see how to add custom CSS. On a block theme, what you change in the Site Editor is saved in the database, and a theme update does not overwrite it.

Can I delete the parent theme once the child is active?

No. The child holds only your changes, and everything else is read from the parent on every page load. Keep the parent installed and keep it updated.

Can a block theme have a child theme?

Yes. A template or template part in the child replaces the parent's file of the same name. Changes made in the Site Editor then sit on top of both. The guide to creating a child theme has a section on block themes.

Not sure what is wrong?

Tell us what you see. We reply with the cause and a fixed quote, and the diagnosis is free.