
Have you ever edited CSS or added code directly to a theme's functions.php? If so, you have probably encountered this painful experience: theme updates wipe out all your customizations. Hours of CSS work gone in an instant the moment you click "Update."
A child theme is the correct, WordPress-standard solution to this problem. This guide explains what a child theme is, how it works, and how to create one from scratch — manually or with a plugin.
Never edit the parent theme directly. Any CSS or PHP changes made to the parent theme files will be overwritten the next time the theme updates. All your work vanishes immediately with no way to recover it.
What Is a WordPress Child Theme?
A child theme is a sub-theme that inherits everything from a parent theme but stores your customizations in its own separate files. This means all your changes are preserved when the parent theme updates, because the update only touches the parent theme's files — never your child theme.
How it works: WordPress loads the child theme first. If it cannot find a requested file in the child theme, it falls back to the parent theme. This lets you override only the parts you need without copying the entire theme.
- Add CSS in child's
style.css→ overrides parent styles - Add PHP in child's
functions.php→ runs alongside parent functions - Copy a template file into the child theme → child version is used instead of parent
Why You Must Create a Child Theme Before Any Customization
There are three core reasons:
- Safe theme updates — All customizations live in the child theme and are never touched by parent theme updates
- Receive security patches — You can update the parent theme to fix vulnerabilities at any time without worrying about losing your work
- Clean separation of customizations — Easier to debug, back up, and migrate because all modifications are in one place
Child Theme File Structure
A child theme requires a minimum of two files in a new folder inside /wp-content/themes/:
/wp-content/themes/
my-parent-theme/ ← Parent Theme (do not edit)
my-parent-theme-child/ ← Our Child Theme
style.css ← Required (Header + Custom CSS)
functions.php ← Recommended (Enqueue Parent CSS)
Creating a Child Theme Manually
Step 1: Create a New Folder
Using DirectAdmin File Manager or FTP, create a new folder inside wp-content/themes/. Name it something like twentytwentyfive-child (if your parent theme is Twenty Twenty-Five).
Step 2: Create style.css
Create a file called style.css in the new folder with this content:
/*
Theme Name: Twenty Twenty-Five Child
Template: twentytwentyfive
Description: Child theme of Twenty Twenty-Five
Author: Your Name
Version: 1.0
*/
/* Add your custom CSS here */
The most important line is Template: — it must exactly match the parent theme's folder name, including capitalization.
Step 3: Create functions.php
Create a functions.php file in the child theme folder to correctly enqueue the parent theme's stylesheet before the child's:
<?php
add_action( 'wp_enqueue_scripts', 'my_child_theme_enqueue_styles' );
function my_child_theme_enqueue_styles() {
// Load Parent Theme stylesheet
wp_enqueue_style(
'parent-style',
get_template_directory_uri() . '/style.css'
);
// Load Child Theme stylesheet (overrides parent)
wp_enqueue_style(
'child-style',
get_stylesheet_directory_uri() . '/style.css',
array( 'parent-style' )
);
}
Note: Many modern themes (Block themes using theme.json) load CSS differently. Some do not require manual wp_enqueue_style for the parent. Always check the theme's documentation to confirm the correct approach.
Activating the Child Theme
- Go to WordPress Admin → Appearance → Themes
- Your new child theme will appear in the list
- Click Activate on the child theme
- Your site looks identical — the child theme inherits everything from the parent
Creating a Child Theme with a Plugin (Child Theme Configurator)
If you prefer not to create files manually, a plugin can handle everything automatically.
Using Child Theme Configurator
- Install the free plugin Child Theme Configurator (400,000+ active installs)
- Go to Tools → Child Theme Configurator
- Select the parent theme you want to use
- Name the child theme and set options
- Click Create Child Theme
- The plugin creates the folder, style.css, and functions.php automatically, then activates the child theme immediately
Adding Custom CSS to Your Child Theme
There are two ways to add custom CSS:
Method 1: Edit style.css Directly
Open style.css in your child theme and add CSS after the comment header:
/* Custom CSS */
.site-header {
background-color: #059669;
}
.entry-title {
font-size: 2rem;
font-weight: 700;
}
Method 2: WordPress Customizer
Go to Appearance → Customize → Additional CSS. This is more convenient but stores CSS in the database rather than in the child theme file.
Overriding Parent Theme Template Files
To change a page layout — for example, the single post template — copy the template file from the parent theme into your child theme folder and edit it there.
# Example: Override Single Post Template
# Copy from parent:
/wp-content/themes/twentytwentyfive/single.php
# Place in child theme:
/wp-content/themes/twentytwentyfive-child/single.php
# Edit single.php in the child theme as needed
# WordPress uses the child theme version automatically
Key rule: Only override files you actually need to change — not the entire theme. Copying everything defeats the purpose of a child theme and you lose the benefit of parent theme updates.
Adding Functions to Child Theme functions.php
The child theme's functions.php runs alongside the parent's — it does not replace it. You can safely add hooks, filters, and custom functions:
<?php
// Add custom analytics script
add_action( 'wp_head', 'my_custom_analytics' );
function my_custom_analytics() {
// Insert analytics or any custom script
}
// Remove sidebar from single posts
add_filter( 'theme_mod_single_sidebar', '__return_false' );
// Register a custom post type
add_action( 'init', 'register_my_custom_post_type' );
function register_my_custom_post_type() {
// ...
}
Using theme.json in a Child Theme (Block Themes)
Since WordPress 5.8, Full Site Editing (FSE) has changed how themes control styles and layouts. Block themes such as Twenty Twenty-Three, Twenty Twenty-Four, and Twenty Twenty-Five use a theme.json file instead of traditional CSS. This means child themes for block-based parents work slightly differently from classic child themes.
In a block theme child theme, you can create your own theme.json to override values defined in the parent. WordPress automatically merges the two files — your child theme values always win. A common use case is changing the site's primary color and typography:
{
"$schema": "https://schemas.wp.org/trunk/theme.json",
"version": 2,
"settings": {
"color": {
"palette": [
{ "name": "Primary", "slug": "primary", "color": "#059669" },
{ "name": "Background", "slug": "background", "color": "#f0fdf4" }
]
},
"typography": {
"fontSizes": [
{ "name": "Small", "slug": "small", "size": "14px" },
{ "name": "Normal", "slug": "normal", "size": "16px" },
{ "name": "Large", "slug": "large", "size": "20px" }
]
}
}
}
The advantage of theme.json overrides is that the Block Editor immediately reflects your custom colors and fonts in the editing interface — keeping the editor and the live site in sync without writing long CSS selectors.
Note: If the parent is a block theme using theme.json, manually enqueueing the parent stylesheet in functions.php may be unnecessary — and could even cause styles to load twice. Always check the parent theme's documentation to confirm the correct approach for child themes.
Comparing Child Theme Creation Methods: Manual, Plugin, and WP-CLI
There are three main ways to create a child theme. Each suits a different situation:
| Method | Best for | Advantages | Watch out for |
|---|---|---|---|
| Manual (style.css + functions.php) | Developers who want full control | No extra plugins; you understand the structure | Easy to mistype the Template header or enqueue order |
| Plugin (Child Theme Configurator) | Non-technical users | One-click setup; GUI options; no typos | Requires installing a plugin; may miss block theme nuances |
| WP-CLI | Developers with SSH access | Fastest; scriptable; repeatable across many sites | Requires WP-CLI and SSH on your hosting server |
For users on shared hosting without SSH access, the manual method via DirectAdmin File Manager or FTP is perfectly practical. Create just two files and you are ready to go. Using WP-CLI, the equivalent single command is:
wp scaffold child-theme twentytwentyfive-child --parent_theme=twentytwentyfive --activate
Common Mistakes and How to Fix Them
Child themes are straightforward to set up, but there are a handful of recurring pitfalls worth knowing before you start:
- "The parent theme is missing" error — The
Template:value instyle.cssdoes not match the parent theme's folder name exactly (including capitalization). Double-check the folder name insidewp-content/themes/. - All parent styles disappear after activation — You forgot to enqueue the parent stylesheet in
functions.php, or used the deprecated@importmethod. Add the correctwp_enqueue_stylecalls. - Child theme appears but does not seem to work — Confirm the child theme is actually active under Appearance → Themes. Also check the PHP error log for syntax errors in
functions.php. - Custom CSS has no effect — The parent theme may use higher-specificity selectors that override yours. Increase your selector specificity, or use WordPress Customizer's Additional CSS field for quick overrides.
- Template override breaks the layout — The copied template file may be outdated if the parent theme updated its template since you copied it. Compare your child theme version with the current parent version and update accordingly.
Debug tip: If the site breaks after activating your child theme, open a private/incognito browser window and go to Appearance → Themes to deactivate the child theme. If the site returns to normal, the issue is in your child theme files — not the server or parent theme.
Backing Up and Maintaining Your Child Theme Long-Term
Your child theme folder holds every customization you have ever made to the site. Losing it — through a failed hosting migration, accidental deletion, or server failure — means losing all your work. Follow these practices to keep it safe:
- Back up the child theme folder separately — Do not rely solely on full-site backups. Zip the child theme folder and save it locally every time you make significant changes.
- Use version control (Git) — Place the child theme folder in a Git repository to track every change and roll back to any previous state instantly.
- Update the parent theme regularly — With a child theme in place, there is no reason to delay security updates. Apply parent theme updates promptly to keep the site protected.
- Review the site after every parent update — Occasionally, a parent theme update changes a template you have overridden. A quick visual check of key pages after each update catches issues early.
- Increment the child theme version number — Change the
Version:value instyle.cssafter significant edits. This busts the browser cache and gives you a clear audit trail of when changes were made.
Bottom line: A child theme requires only two files to get started but provides long-term protection that every WordPress site deserves. If your site is currently running without a child theme, create one now — before the next theme update wipes out your hard work.
WordPress Hosting with Full File Access — from 500 THB/year
AsiaGB Hosting fully supports WordPress child themes with DirectAdmin, SSD storage, free SSL, File Manager, and FTP access. Starting at 500 THB/year with no hidden fees.
View Hosting Plans →