Child themes are one of those WordPress concepts that sound more complicated than they are. If you've ever customized a theme directly and then lost all your changes after an update, you already understand why child themes exist. They let you modify any WordPress theme without touching the original files, so updates never overwrite your work.
This guide walks through what child themes are, the minimum files you need to create one, and how to override styles and templates properly.
Why Child Themes Exist
WordPress themes get regular updates for security patches, bug fixes, and new features. When you modify a theme's files directly and then update that theme, WordPress replaces those files with fresh copies from the update. Every customization you made disappears.
A child theme sits on top of a parent theme and inherits all its functionality. You make your changes in the child theme, and WordPress automatically uses your versions instead of the parent's. When the parent theme updates, your child theme stays intact.
Child themes also make customization safer. If you break something in your child theme, you can simply deactivate it and fall back to the parent. You're never editing files that other sites depend on or that the theme developer maintains.
Common scenarios where child themes are essential:
- Custom CSS that goes beyond what the theme customizer offers
- Modified page templates for specific layouts
- Custom PHP functions that extend theme behavior
- Changed header, footer, or sidebar templates
- Sites managed by agencies who need update-proof customizations
Minimum Files Required
A WordPress child theme needs exactly two files to function: style.css and functions.php. Everything else is optional and only created when you need to override something specific.
The Directory Structure
Create a new folder in wp-content/themes/ with a name that identifies it as a child theme. If your parent theme is Twenty Twenty-Four, name it something like twentytwentyfour-child.
wp-content/themes/
├── twentytwentyfour/ (parent theme)
└── twentytwentyfour-child/ (your child theme)
├── style.css
└── functions.php
style.css — The Required Header
The style.css file must include a specific header comment that tells WordPress this is a child theme and which parent it depends on.
/*
Theme Name: Twenty Twenty-Four Child
Template: twentytwentyfour
Description: Custom child theme for Twenty Twenty-Four
Author: Your Name
Version: 1.0.0
*/
/* Your custom CSS goes here */
The two critical fields are:
- Theme Name: Whatever you want to call your child theme
- Template: The directory name of the parent theme (case-sensitive)
Get the Template value wrong and WordPress won't know which parent to load. You can find the correct directory name by looking in wp-content/themes/ or checking the parent theme's style.css header.
functions.php — Enqueuing Stylesheets
The functions.php file loads the parent theme's stylesheet and then your child theme's stylesheet. Never use @import in CSS for this; it's slower and causes loading order issues.
<?php
function child_theme_enqueue_styles() {
wp_enqueue_style('parent-style', get_template_directory_uri() . '/style.css');
wp_enqueue_style('child-style', get_stylesheet_uri(), array('parent-style'));
}
add_action('wp_enqueue_scripts', 'child_theme_enqueue_styles');
This code uses WordPress's enqueue system to load stylesheets in the right order. The parent loads first, then your child theme CSS loads second so it can override parent rules.
Some modern themes handle stylesheet loading differently, especially block themes. Check your parent theme's documentation to see if it requires a specific enqueue approach.
Activating Your Child Theme
Once both files exist, the child theme appears in Appearance → Themes in your WordPress admin. Activate it like any other theme.
WordPress automatically pulls in all the parent theme's templates, functions, and assets. Your child theme doesn't need to duplicate anything unless you're changing it.
If you see a broken theme or an error message, double-check:
- The
Templatefield instyle.cssexactly matches the parent theme's directory name - Both
style.cssandfunctions.phpare in the child theme root, not a subfolder - The parent theme is still installed in
wp-content/themes/
Overriding Parent Styles
Every CSS rule you add to your child theme's style.css loads after the parent's styles, so you can override any parent rule using standard CSS specificity.
Basic Style Override
If the parent theme sets heading colors like this:
h1, h2, h3 {
color: #333333;
}
Your child theme can override it:
h1, h2, h3 {
color: #0073aa;
}
Because your child stylesheet loads second, your rule wins.
Dealing with Specificity
Sometimes parent styles use high-specificity selectors that are hard to override. You have three options:
- Match or exceed the specificity — If the parent uses
.site-header .main-nav a, use the same selector or something more specific - Use a more specific selector — Add an ID or extra class to increase weight
- Use
!importantas a last resort — Only when the parent also uses!importantor you can't increase specificity otherwise
Inspect the element in your browser's developer tools to see the parent's selector and specificity.
Organizing Child Theme CSS
For maintainability, organize your custom CSS with comments:
/* ==========================================================================
Typography
========================================================================== */
h1, h2, h3 {
color: #0073aa;
}
/* ==========================================================================
Header Customizations
========================================================================== */
.site-header {
background-color: #ffffff;
border-bottom: 1px solid #e5e5e5;
}
This makes it easier to find and update rules months later.
Overriding Template Files
WordPress follows a template hierarchy when rendering pages. If a template exists in the child theme, WordPress uses it. Otherwise, it falls back to the parent.
How to Override a Template
- Find the template file you want to change in the parent theme
- Copy it to your child theme, maintaining the same file path
- Edit the child theme version
For example, to customize the footer:
- Locate
wp-content/themes/twentytwentyfour/footer.php - Copy it to
wp-content/themes/twentytwentyfour-child/footer.php - Modify the child copy
WordPress now uses your child version instead of the parent's.
Template Hierarchy Examples
Common templates you might override:
header.php— Site headerfooter.php— Site footersidebar.php— Sidebar contentsingle.php— Single post layoutpage.php— Default page layoutarchive.php— Archive pages404.php— Not found page
For custom page templates, copy the parent's template and change the template name comment at the top:
<?php
/**
* Template Name: Custom Landing Page
*/
get_header();
// Your custom template code
get_footer();
Maintaining Templates
The downside of overriding templates is that you take on maintenance responsibility. If the parent theme updates a template to fix a security issue or add new features, your override won't get those changes automatically.
Best practices:
- Only override templates when CSS alone can't achieve what you need
- Keep overrides minimal — change only what's necessary
- Review parent theme changelogs when updating to see if overridden templates changed
- Test your site after parent theme updates
Adding Custom Functions
Beyond styles and templates, your child theme's functions.php can add or modify functionality.
Adding Custom Code
Any code you add to functions.php runs after the parent theme's functions file loads. This means you can:
- Register custom widget areas
- Add new image sizes
- Modify theme support features
- Hook into WordPress actions and filters
- Override parent theme functions (if they're pluggable)
<?php
// Enqueue scripts and styles (required)
function child_theme_enqueue_styles() {
wp_enqueue_style('parent-style', get_template_directory_uri() . '/style.css');
wp_enqueue_style('child-style', get_stylesheet_uri(), array('parent-style'));
}
add_action('wp_enqueue_scripts', 'child_theme_enqueue_styles');
// Add custom widget area
function child_theme_widgets_init() {
register_sidebar(array(
'name' => 'Custom Sidebar',
'id' => 'custom-sidebar',
'before_widget' => '<div class="widget">',
'after_widget' => '</div>',
));
}
add_action('widgets_init', 'child_theme_widgets_init');
// Change excerpt length
function child_theme_excerpt_length($length) {
return 30;
}
add_filter('excerpt_length', 'child_theme_excerpt_length');
Overriding Parent Functions
Some parent themes wrap functions in if (!function_exists()) checks, making them pluggable. You can override these by defining the same function in your child theme.
Check the parent's functions.php to see which functions are pluggable. If a function isn't wrapped in that check, you can't override it directly — you'll need to use hooks instead.
Including Additional Assets
Child themes can include their own JavaScript, images, fonts, and additional CSS files.
Adding JavaScript
Enqueue custom scripts in functions.php:
function child_theme_enqueue_scripts() {
wp_enqueue_script(
'child-custom-js',
get_stylesheet_directory_uri() . '/js/custom.js',
array('jquery'),
'1.0.0',
true
);
}
add_action('wp_enqueue_scripts', 'child_theme_enqueue_scripts');
Place your JavaScript file at wp-content/themes/child-theme-name/js/custom.js.
Loading Additional Stylesheets
For better organization, you might split CSS into multiple files:
function child_theme_enqueue_styles() {
wp_enqueue_style('parent-style', get_template_directory_uri() . '/style.css');
wp_enqueue_style('child-style', get_stylesheet_uri(), array('parent-style'));
wp_enqueue_style(
'child-custom-styles',
get_stylesheet_directory_uri() . '/css/custom.css',
array('child-style')
);
}
Referencing Child Theme Assets
Use these functions to build correct paths:
get_stylesheet_directory_uri()— Child theme URLget_stylesheet_directory()— Child theme server pathget_template_directory_uri()— Parent theme URLget_template_directory()— Parent theme server path
Common Mistakes to Avoid
Using @import in CSS: Slows page load because stylesheets load sequentially instead of in parallel. Always enqueue in functions.php instead.
Wrong Template value: If Template: doesn't exactly match the parent theme's directory name, the child theme breaks. Check capitalization and spelling.
Editing parent theme files: Defeats the purpose. Make changes in the child theme only.
Overriding too many templates: Creates maintenance burden. Use CSS and hooks when possible; override templates only when necessary.
No version control: Track your child theme in Git. When something breaks after an update, you can see exactly what changed.
Skipping testing after parent updates: Parent theme updates can change template structure or CSS selectors. Test your site after updating.
Conclusion
Child themes are the professional way to customize WordPress. With just two files — style.css and functions.php — you can override any aspect of a parent theme while keeping your changes update-proof. Start with basic CSS overrides, add template modifications only when necessary, and test after parent theme updates. Your future self will thank you when an update doesn't wipe out months of customization work.
