WordPress Child Themes - What They Are and How to Create One
A child theme lets you customise WordPress without losing changes on updates. How to create one, what to put in it, and when you actually need one.
If you modify a WordPress theme's files directly, those modifications are overwritten the next time the theme updates. A child theme is the solution: it inherits all the parent theme's styles and functionality while keeping your customisations in separate files that are never touched by parent theme updates.
This guide explains how child themes work, when you need one, and how to create one from scratch.
How child themes work
A child theme is a separate theme folder that declares a parent theme. WordPress loads the child theme's files in place of the parent's. If the child theme does not have a file, WordPress falls back to the parent.
The hierarchy works like this:
- WordPress looks for the file in the child theme
- If not found, it uses the parent theme's version
- For
functions.php, both files are loaded (child'sfunctions.phploads first, then parent's)
This means:
- Modify
header.php: copy it to the child theme and edit the copy - Add a custom function: add it in the child theme's
functions.php - Override a style: add your CSS rules to the child theme's
style.css(they load after the parent's, so they override)
When you need a child theme
You need a child theme if:
- You are modifying a third-party theme's PHP template files
- You are adding custom functions that should survive theme updates
- The theme does not have a dedicated customisation API
You do not need a child theme if:
- You are only adding custom CSS (use the WordPress Customizer > Additional CSS instead)
- You are using a page builder that stores all customisations in the database (Elementor, Bricks, Breakdance store their data as post meta - not in theme files)
- You are building a completely custom theme from scratch (just build the theme, not a child theme)
- The theme provides a "child theme" plugin or API for customisations
Creating a child theme manually
Step 1 - Create the child theme directory
In /wp-content/themes/, create a new folder. Name it after the parent theme with -child appended:
wp-content/themes/ ├── twentytwentyfour/ (parent theme) └── twentytwentyfour-child/ (your child theme)
Step 2 - Create style.css
Inside the child theme folder, create style.css. The comment block at the top is what WordPress reads to identify the theme:
/* Theme Name: Twenty Twenty-Four Child Theme URI: https://yourdomain.com/ Description: Child theme for Twenty Twenty-Four Author: Your Name Template: twentytwentyfour Version: 1.0.0 Text Domain: twentytwentyfour-child */ /* Your custom styles go below this line */
The Template: field must exactly match the parent theme's folder name. This is case-sensitive.
Step 3 - Create functions.php
Create functions.php in the child theme folder. Add the code to enqueue the parent theme's stylesheet:
<?php
add_action( 'wp_enqueue_scripts', function() {
// Enqueue parent theme stylesheet
wp_enqueue_style(
'parent-style',
get_template_directory_uri() . '/style.css'
);
});
get_template_directory_uri() points to the parent theme directory. get_stylesheet_directory_uri() points to the child theme directory.
This distinction matters when you need to reference files in each theme.
Step 4 - Activate the child theme
Go to Appearance > Themes in the WordPress admin. You should see your child theme listed. Activate it.
Verify it is working: the site should look identical to before (the child theme inherits all parent styles). If it looks broken, check that the Template: value in style.css exactly matches the parent theme folder name.
Adding customisations
Override a template file
To modify a template file (e.g., single.php):
- Find the file in the parent theme:
wp-content/themes/parenttheme/single.php - Copy it to the child theme:
wp-content/themes/parenttheme-child/single.php - Edit the copy
WordPress now uses the child theme's version. The parent theme's file is ignored for this template. When the parent theme updates, your child theme file is not changed.
Add custom PHP functions
All custom functions go in the child theme's functions.php. Examples:
<?php
// Remove the default header image
add_action( 'init', function() {
remove_theme_support( 'custom-header' );
});
// Add custom image size
add_action( 'after_setup_theme', function() {
add_image_size( 'custom-card', 600, 400, true );
});
// Customize the excerpt length
add_filter( 'excerpt_length', function() {
return 20;
});
// Add custom body class
add_filter( 'body_class', function( $classes ) {
$classes[] = 'my-custom-class';
return $classes;
});
Add custom styles
In the child theme's style.css, add your CSS overrides after the comment block:
/* Override parent theme card styles */
.post-card {
border-radius: 4px;
border: 1px solid #e0e0e0;
}
/* Custom header height */
.site-header {
height: 80px;
}
These rules load after the parent's stylesheet and override matching selectors.
Child themes for popular theme frameworks
Astra
Astra is one of the most popular parent theme frameworks. Their recommended approach is to use their own child theme generator at wpastra.com/child-theme-generator. This creates a ready-made child theme with the correct template name and a placeholder functions.php.
GeneratePress
GeneratePress users should install the GP Premium plugin, which includes its own customisation system. For deeper customisation, create a child theme as described above.
Divi
Divi (by Elegant Themes) has its own child theme approach. Elegant Themes provides a blank child theme download that correctly inherits Divi's styles. Download it from your Elegant Themes account rather than creating from scratch.
A note on block themes (FSE)
WordPress Full Site Editing themes (like Twenty Twenty-Four) work differently from classic themes. They store templates as HTML files in the theme's templates/ directory rather than PHP templates.
For block themes:
- CSS overrides still work in the child theme's
style.css - Template overrides work by copying the template HTML files to the child theme's
templates/folder - The
theme.jsonfile (which controls the block editor's design system) can be overridden or extended in the child theme
The functions.php approach is the same for both classic and block themes.
Quick reference: child theme file structure
A minimal child theme for a theme called parenttheme:
wp-content/themes/parenttheme-child/
├── style.css (required - theme declaration and custom CSS)
├── functions.php (required - enqueue parent styles, add PHP hooks)
├── screenshot.png (optional - shows in Themes admin, 1200x900px)
└── templates/ (optional - override parent theme templates)
└── single.php
That is it. The simplest functional child theme is two files: style.css and functions.php.
Related reading
// new_articles
Get notified when new guides drop
Practical WordPress guides from a working agency owner. No filler. Unsubscribe any time.
Was this article helpful?
Thanks for the feedback!