In this guide: How to use a child theme in WordPress: what a child theme is, when you need one, how to create it, adding custom CSS and functions, and common mistakes.
You customize your WordPress theme — edit a template, add CSS, tweak a function — and everything looks perfect. Then the theme updates and all your changes disappear. A child theme prevents that.
A child theme is a theme that inherits everything from another theme (the parent) while letting you override specific parts.
WordPress loads the child theme’s files first. If a file exists in the child theme, it’s used; if not, WordPress falls back to the parent.
You need a child theme if you plan to:
header.php, single.php, or block theme templates stored as files).You may not need one if you only:
Block themes: changes made in the Site Editor are saved in the database, so they survive updates. However, a child theme is still useful if you want to version-control templates and theme.json changes in files.
A basic child theme needs just two files.
1. Create a folder in /wp-content/themes/, for example: astra-child (use the parent’s folder name plus -child).
2. Create style.css:
/*
Theme Name: Astra Child
Template: astra
Version: 1.0.0
Description: Child theme for customizations
*/
The Template line must exactly match the parent theme’s folder name (not its display name).
3. Create functions.php to load styles (for classic themes):
<?php
add_action( 'wp_enqueue_scripts', function () {
wp_enqueue_style(
'child-style',
get_stylesheet_uri(),
array(),
wp_get_theme()->get( 'Version' )
);
} );
Many modern parent themes already load their own stylesheet correctly; check the parent theme’s documentation — some recommend also enqueuing the parent stylesheet explicitly.
4. Upload and activate: zip the folder and upload via Appearance → Themes → Add New → Upload, or upload via SFTP. Then activate the child theme.
Shortcut: many popular themes provide a ready-made child theme download, and there are plugins that generate child themes for you.
Important: after switching to a child theme, some Customizer settings may need to be re-applied or imported, since they’re stored per theme.
CSS: add rules to your child theme’s style.css:
.site-header {
background: #0B0F14;
}
.button {
border-radius: 10px;
}
Override templates: copy a template file from the parent (for example, footer.php) into the child theme and edit the copy.
Functions: add PHP to the child theme’s functions.php. Unlike templates, the child’s functions.php doesn’t replace the parent’s — both load (child first).
// Change excerpt length
add_filter( 'excerpt_length', fn() => 25 );
For block themes, you can add a theme.json in the child theme to override colors, typography, and spacing, and copy template files from the parent’s templates folder to customize them.
Further reading: official WordPress documentation
style.css (with the correct Template line) and usually functions.php.We may earn a commission on purchases made through these links, at no extra cost to you.
Don’t miss the chance to participate in the biggest giveaway of this year.