How to Create a Child Theme in WordPress: A Complete Step-by-Step Guide
Customizing a WordPress theme is one of the easiest ways to change the appearance and functionality of a website. However, directly modifying files in a parent theme can create problems when the theme receives an update. Your custom changes may be overwritten, forcing you to redo your work.
A WordPress child theme solves this problem. It allows you to customize an existing theme while keeping your modifications separate from the original theme files.
In this guide, you will learn what a child theme is, why you should use one, how to create it manually, and how to customize it safely.
What Is a WordPress Child Theme?
A child theme is a separate WordPress theme that inherits most of its design and functionality from another theme called the parent theme.
The child theme can contain its own:
- CSS styles
- PHP functions
- Template files
- JavaScript
- Images
- Customizations
When WordPress loads the website, it uses the child theme first and falls back to the parent theme when a particular file or function is not available.
For example:
Parent Theme
↓
Child Theme
↓
Your Custom Changes
This structure allows you to modify the website without changing the original theme.
Why Should You Use a Child Theme?
A child theme is particularly useful when you plan to make code-level customizations.
1. Protects Your Customizations
The biggest advantage is that your changes remain separate from the parent theme.
If the parent theme is updated, your custom CSS, templates, and functions stored in the child theme normally remain intact.
2. Makes Theme Updates Safer
Theme developers regularly release updates containing security fixes, bug fixes, and compatibility improvements. Updating a modified parent theme can overwrite your changes.
With a child theme, you can update the parent theme without replacing your custom files.
3. Makes Customization Easier to Manage
Instead of modifying dozens of original theme files, you can keep your customizations inside the child theme.
This makes troubleshooting and maintenance easier.
4. Allows Template Overrides
You can copy selected template files from the parent theme into the child theme and customize them.
For example:
parent-theme/single.php
can be copied to:
child-theme/single.php
WordPress will generally use the child version instead of the parent’s version.
What You Need Before Creating a Child Theme
Before getting started, make sure you have:
- A WordPress website
- An installed parent theme
- Access to your WordPress files
- Access to your hosting control panel, FTP, or file manager
- Basic knowledge of CSS and PHP if you plan to make advanced changes
You should also create a backup before modifying theme files.
Step 1: Identify the Parent Theme
First, determine the theme currently installed on your website.
Go to:
WordPress Dashboard → Appearance → Themes
Find the theme you want to customize.
For example, suppose your parent theme is:
mytheme
Its theme directory might be:
/wp-content/themes/mytheme/
The exact directory name depends on the theme.
Step 2: Create a Child Theme Directory
Open your WordPress installation’s:
wp-content/themes/
directory.
Create a new folder for your child theme.
For example:
mytheme-child
Your directory structure should now look similar to:
wp-content/
└── themes/
├── mytheme/
└── mytheme-child/
Using a descriptive folder name makes it easier to identify the relationship between the parent and child themes.
Step 3: Create the style.css File
Inside the child theme directory, create a file named:
style.css
Add a theme header similar to this:
/*
Theme Name: MyTheme Child
Theme URI: https://example.com/
Description: Child theme for MyTheme
Author: Your Name
Author URI: https://example.com/
Template: mytheme
Version: 1.0.0
*/
The most important line is:
Template: mytheme
The value must match the directory name of the parent theme, including capitalization where applicable.
For example, if the parent theme directory is:
generatepress
the child theme should contain:
Template: generatepress
A mismatch here can prevent WordPress from recognizing the parent theme correctly.
Step 4: Add Your Custom CSS
You can place your custom CSS below the theme header.
For example:
.site-title {
font-size: 32px;
font-weight: 700;
}
.site-header {
padding: 20px;
}
This allows you to customize elements without editing the parent theme’s stylesheet directly.
However, how stylesheets are loaded can vary between classic and block themes, so for modern WordPress themes you should follow the parent theme’s recommended child-theme setup where applicable.
Step 5: Create functions.php
Create another file inside your child theme:
functions.php
Unlike the parent theme’s functions.php, you should not simply copy the entire parent functions.php file into the child theme.
Instead, the child theme’s functions.php is loaded in addition to the parent theme’s functions file.
A basic example is:
<?php
function mytheme_child_setup() {
// Add child theme customizations here.
}
add_action('after_setup_theme', 'mytheme_child_setup');
You can use this file for custom functionality, hooks, filters, and other PHP-based modifications.
Step 6: Load the Parent Stylesheet Properly
For many classic themes, styles can be loaded using wp_enqueue_style().
A typical example is:
<?php
function mytheme_child_enqueue_styles() {
wp_enqueue_style(
'parent-style',
get_template_directory_uri() . '/style.css'
);
wp_enqueue_style(
'child-style',
get_stylesheet_directory_uri() . '/style.css',
array('parent-style'),
wp_get_theme()->get('Version')
);
}
add_action('wp_enqueue_scripts', 'mytheme_child_enqueue_styles');
This tells WordPress to load the parent stylesheet before the child stylesheet.
Important: Some modern themes use different styling systems, especially block themes. In those cases, copying a traditional child-theme setup may not be appropriate. Check the theme’s documentation before changing its stylesheet-loading method.
Step 7: Activate the Child Theme
After creating the required files, return to your WordPress Dashboard.
Go to:
Appearance → Themes
You should see your child theme listed.
Select it and click:
Activate
Your website should continue using the parent theme’s design while allowing you to add customizations through the child theme.
Step 8: Test the Child Theme
Visit your website after activating the child theme.
Check:
- Homepage
- Blog posts
- Pages
- Navigation menus
- Widgets
- Header
- Footer
- Mobile layout
- Forms
- Images
- Custom functionality
If something looks incorrect, check whether the parent stylesheet has been loaded correctly.
Step 9: Override a Parent Template
One of the most useful features of a child theme is template overriding.
Suppose the parent theme contains:
single.php
You can copy that file into:
mytheme-child/single.php
Then modify the child version.
WordPress will generally use the child theme’s single.php instead of the parent version.
For example:
wp-content/
└── themes/
├── mytheme/
│ └── single.php
│
└── mytheme-child/
├── style.css
├── functions.php
└── single.php
This gives you control over the post template without changing the original theme file.
Step 10: Add Custom JavaScript
If your customization requires JavaScript, create a file such as:
script.js
inside the child theme.
Then enqueue it from functions.php:
function mytheme_child_scripts() {
wp_enqueue_script(
'mytheme-child-script',
get_stylesheet_directory_uri() . '/script.js',
array(),
wp_get_theme()->get('Version'),
true
);
}
add_action('wp_enqueue_scripts', 'mytheme_child_scripts');
This approach is preferable to inserting JavaScript directly into theme templates.
Example Child Theme Structure
A simple child theme might look like this:
mytheme-child/
│
├── style.css
├── functions.php
├── script.js
├── single.php
└── images/
You don’t need to create every file from the parent theme. Only add the files you actually need to customize.
How to Create a Child Theme Using a Plugin
If you don’t want to manually create theme files, you can use a WordPress child-theme plugin.
The general process is:
- Open Plugins → Add New Plugin.
- Search for a reputable child-theme creation plugin.
- Install and activate it.
- Select your parent theme.
- Configure the child theme options.
- Generate the child theme.
- Activate the new child theme.
- Test your website.
Always check the plugin’s compatibility and maintenance status before installing it.
For a production website, creating a simple child theme manually can also be a straightforward option.
Child Theme vs Parent Theme
| Feature | Parent Theme | Child Theme |
|---|---|---|
| Original theme files | Yes | No |
| Inherits design | N/A | Yes |
| Safe place for custom code | Limited | Yes |
| Parent updates | Can overwrite direct edits | Usually preserves child files |
| Template overrides | Original templates | Can override selected templates |
| Requires parent theme | No | Yes |
Common Child Theme Mistakes
1. Incorrect Template Name
One of the most common mistakes is using the wrong value for:
Template:
It must match the parent theme’s directory name.
Incorrect:
Template: My Theme
Correct example:
Template: mytheme
2. Copying the Parent functions.php
Don’t copy the complete parent functions.php into the child theme.
The child functions file works alongside the parent functions file. Copying everything can cause duplicate function declarations and other conflicts.
3. Editing the Parent Theme
Once the child theme is active, avoid modifying the parent theme unless there is a specific reason.
Store your custom CSS, PHP, templates, and scripts in the child theme whenever practical.
4. Forgetting to Back Up the Website
Before changing PHP or template files, create a backup.
A PHP syntax error can sometimes make parts of the website inaccessible. Having a backup gives you a way to recover quickly.
5. Overriding Too Many Files
A child theme doesn’t mean you should copy the entire parent theme.
Only override the files that actually require customization.
The fewer files you maintain, the easier future theme updates and troubleshooting become.
What Happens When the Parent Theme Is Updated?
One of the main reasons to use a child theme is to separate your customizations from the parent theme.
For example:
Parent Theme
↓
Theme Update
↓
Original files replaced
Your child theme remains separate:
Child Theme
↓
Your custom CSS
Your custom PHP
Your template overrides
Your JavaScript
↓
Remain in place
However, a child theme does not guarantee that every update will be completely problem-free. If the parent theme significantly changes its templates, hooks, CSS classes, or functionality, your child-theme customizations may need to be updated as well.
When Should You Use a Child Theme?
A child theme is particularly useful when you need to:
- Modify theme templates
- Add custom PHP functionality
- Override template files
- Add custom JavaScript
- Make extensive CSS modifications
- Customize theme hooks and filters
- Maintain changes across parent-theme updates
For small CSS-only changes, the WordPress Customizer or Site Editor may be sufficient, depending on the theme.
Child Themes and Block Themes
Modern WordPress includes block themes, which use the Site Editor and block templates rather than relying exclusively on traditional PHP template files.
If you’re using a block theme, the customization workflow can be different. You may work with:
theme.json- Block templates
- Template parts
- Global styles
- Site Editor customization
Therefore, before creating a traditional PHP-based child theme, determine whether your theme is a classic theme or a block theme.
How to Troubleshoot a Child Theme
If the child theme doesn’t work as expected, check the following.
Child theme doesn’t appear
Verify that:
style.css
exists inside the child theme directory and contains a valid theme header.
Parent theme isn’t recognized
Check:
Template: parent-folder-name
Make sure the value exactly matches the parent theme directory.
Website styling is broken
Check whether the parent stylesheet is being loaded correctly and inspect the browser’s developer tools for CSS errors.
PHP error appears
Review the latest code added to functions.php. A missing bracket, semicolon, or incorrectly declared function can cause PHP errors.
Changes aren’t visible
Clear:
- WordPress cache
- Browser cache
- CDN cache, if applicable
Then reload the page.
Best Practices for WordPress Child Themes
Follow these practices to keep your child theme maintainable:
- Back up the website before making changes.
- Keep the child theme lightweight.
- Avoid modifying parent theme files directly.
- Use WordPress hooks and filters when possible.
- Use
wp_enqueue_style()andwp_enqueue_script()for assets. - Don’t duplicate the entire parent theme.
- Keep custom PHP organized and documented.
- Test changes on a staging website when possible.
- Check compatibility after major parent-theme updates.
- Keep WordPress, themes, and plugins updated.
Final Thoughts
Creating a WordPress child theme is a practical way to make deeper theme customizations while keeping your changes separate from the original theme. Instead of editing the parent theme directly, you can place custom CSS, PHP, JavaScript, and selected template overrides inside the child theme.
The basic process is straightforward: create a child-theme directory, add style.css and functions.php, correctly identify the parent theme, activate the child theme, and then add only the customizations you need.
For websites that require ongoing customization, this approach can make theme maintenance considerably more organized and reduce the risk of losing custom work during parent-theme updates.