If you edit a theme’s files directly, the next theme update overwrites your changes. A child theme solves this: it inherits everything from the parent theme, and only contains the files you change. WordPress loads the child’s files first, and falls back to the parent for everything else.
When you need one
- You change template files (
header.php,single.php, block templates). - You add PHP to
functions.php. - You add more than a few lines of CSS.
You don’t need one for: small CSS tweaks (use Appearance → Customize → Additional CSS, or the Site Editor’s styles), or functionality that isn’t theme-related (put that in a small site-specific plugin instead, so it survives a theme switch).
Create a child theme (classic theme)
Example for a parent theme in wp-content/themes/parent-theme:
cd /var/www/example.com/wp-content/themes
mkdir parent-theme-child && cd parent-theme-child
style.css (the header is required):
/*
Theme Name: Parent Theme Child
Template: parent-theme
Version: 1.0.0
Description: Child theme for Parent Theme
*/
/* your custom CSS below */
Template must be the folder name of the parent theme, exactly.
functions.php (load the parent’s styles, then the child’s):
<?php
add_action( 'wp_enqueue_scripts', function () {
$parent = 'parent-style';
wp_enqueue_style( $parent, get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-style', get_stylesheet_uri(), [ $parent ], wp_get_theme()->get( 'Version' ) );
} );
Many modern parent themes already enqueue their stylesheet properly. Check the theme’s documentation to avoid loading it twice.
Activate it in Appearance → Themes, or with WP-CLI:
sudo chown -R www-data:www-data /var/www/example.com/wp-content/themes/parent-theme-child
wp theme activate parent-theme-child
Add a screenshot.png (1200×900) if you want a thumbnail in the theme list.
Overriding templates
Copy the template file from the parent to the same relative path in the child, then edit the copy:
cp ../parent-theme/template-parts/footer.php template-parts/footer.php
When the parent theme updates a file you’ve overridden, you won’t get those changes. Keep overrides few, and compare them after major parent updates.
Child themes for block themes
Block themes (Twenty Twenty-Four, Twenty Twenty-Five, and others) use theme.json and HTML templates:
parent-theme-child/
├── style.css # header with Template: twentytwentyfive
├── theme.json # only the settings and styles you change
├── templates/ # overrides, e.g. single.html
└── parts/ # overrides, e.g. footer.html
A minimal theme.json:
{
"$schema": "https://schemas.wp.org/trunk/theme.json",
"version": 3,
"settings": {
"color": { "palette": [ { "slug": "brand", "color": "#1d4ed8", "name": "Brand" } ] }
},
"styles": {
"typography": { "fontSize": "1.05rem" }
}
}
The child’s theme.json is merged with the parent’s. Templates edited in the Site Editor are stored in the database, not in files. Use the Create Block Theme plugin to export those changes into your child theme’s files.
Generate one with WP-CLI
wp scaffold child-theme parent-theme-child --parent_theme=parent-theme --activate
(Creates style.css, functions.php and an enqueue setup.)
Version control and deployment
Keep the child theme in Git, and deploy it like code instead of editing files in wp-admin. Disable the built-in file editor with DISALLOW_FILE_EDIT. See WordPress Git deployment and wp-config.php tweaks.
Common problems
| Problem | Fix |
|---|---|
| “The parent theme is missing” | Template: doesn’t match the parent’s folder name |
| Styles missing or doubled | Check how the parent enqueues its CSS; adjust functions.php |
| Changes not visible | Clear page and browser caches; check CSS specificity |
| Override ignored | File path in the child must mirror the parent exactly |
Fatal error after editing functions.php |
Fix via SSH. See WordPress critical error |
Quick reference
| File | Purpose |
|---|---|
style.css |
Header (Template: = parent folder) + CSS |
functions.php |
Enqueue styles, add hooks |
| Same-path templates | Override parent templates |
theme.json |
Block theme settings and styles |
| WP-CLI | wp scaffold child-theme |
Related: WordPress hooks: actions and filters and Gutenberg vs Elementor.