Child themes are extensions of a parent theme. They allow you to modify an existing theme without directly editing that theme’s code. They are often something as simple as a few minor color changes, but they can also be complex and include custom overrides of the parent theme.
In this article, you will learn what parent and child themes are, how to create your own modifications via child themes, and what pieces of a parent theme that can be overridden.
What are parent and child themes?
Parent themes
All themes—unless they are specifically a child theme—are technically parent themes. Basically, this means that they are complete themes that can be installed and activated in WordPress.
Parent themes must have all of the required files, as outlined in the Theme Structure documentation. Beyond that, you don’t have to do anything special for your theme to become a parent theme.
Child themes
A child theme includes everything from its parent theme by default. This includes the design and any of its functionality. But it can also be used to make customizations to the parent theme without directly modifying the parent theme’s files. This means that you (or your child theme’s users) can still receive updates to the parent theme without losing those modifications.
Child themes:
- Make your modifications portable and replicable.
- Keep customizations separate from the parent theme.
- Allow parent themes to be updated without losing your modifications.
- Save on development time since you’re only writing the code you need.
- Are a great way to start your journey toward developing full themes.
It’s worth noting that making extensive customizations from within a child theme can eventually become a management headache. For these more extensive projects, it is often better to fork the original theme and create a full/parent theme of your own. This is something you will need to decide on a case-by-case basis.
What about grandchild themes?
This is not currently possible. There are only two levels to the standard theme hierarchy: parent and child theme.
However, when building block themes, there are other levels to what is presented on the front end of a site (they are just not a part of the theme layer):
- WordPress itself (default
theme.json
) - Parent theme
- Child theme
- User customizations (can override
theme.json
, templates, and patterns)
In a way, the user customization layer works as a “grandchild” theme of sorts. The big difference is that the changes are stored in the database instead of the filesystem.
Outside of that, there is no standard method of creating an installable grandchild theme.
How to create a child theme
Let’s try creating a child theme of the default Twenty Twenty-Four theme bundled with WordPress.
Create a child theme folder
First, your child theme needs a name. This can be whatever you want your theme to be called, but for this guide, let’s name it “Grand Sunrise.”
Now create a new folder in your wp-content/themes
directory with a kebab-case version of your theme name: grand-sunrise
.
Create a style.css
Now you’ll need to create a file named style.css
. It is the one absolutely necessary file for a child theme to exist. All style.css
files must contain a File Header and the required header fields, as outlined in the Main Stylesheet documentation (please review this doc if you have not already done so).
As noted in the Main Stylesheet documentation, there is an additional field necessary to declare a theme as a child theme. You must add the Template
header field to the style.css
File Header:
/**
* Theme Name: Grand Sunrise
* Template: twentytwentyfour
* ...other header fields
*/
There is one caveat to the Template
field. It must be a 100% match of the folder name of the parent theme, relative to the wp-content/themes
folder. In this case, we know that the Twenty Twenty-Four theme folder is located at wp-content/themes/twentytwentyfour
. Therefore, the Template
value must be twentytwentyfour
.
Install and activate child theme
If you are not already working within a development environment with your theme in the wp-content/themes
folder, you’ll need to move it there now. Depending on your setup, you have several options, but the easiest is to create a ZIP file of your theme and upload it to your test site via Appearance > Themes > Add New in your WordPress admin.
For more information on how to add a theme to a WordPress, read Adding New Themes from the WordPress Documentation site.
Once your theme is installed, visit Appearance > Themes in your WordPress admin and locate your theme. Click the Activate link as shown in this screenshot: