Planning to change your theme's code or styles? Then you should know about a child theme first. A child theme is a theme that borrows all the features and design of another theme, called the parent theme.
It lets you customize your site safely. When the parent theme gets an update, the changes in your child theme stay untouched.
Why do you need a child theme?
If you edit the parent theme's files directly, the next update replaces those files with fresh copies. All your hard work vanishes in a second. That is why I always put my own style changes in a child theme.
A child theme keeps your edits in a separate folder, so updates cannot touch them. Just like a child inherits features from its parents but still has its own style, a child theme inherits everything and changes only what you want.
How does a child theme work?
WordPress uses the parent theme as the base and applies the child theme on top of it. If the child folder has a template file with the same name, such as single.php, WordPress uses the child's version instead.
The child's functions.php file doesn't replace the parent's. Both files load, so you can add new code without copying the old code.
What files does a child theme need?
A basic child theme is pretty simple. It sits in its own folder inside /wp-content/themes/ and usually has just two files:
style.csswith a header that names the parent folder, for exampleTemplate: twentytwentyone.functions.phpto load the parent theme's stylesheet and any extra code.
After that, you activate the child theme from Appearance → Themes like any other theme. Our step-by-step guide shows how to create a child theme in WordPress.
Keep the parent theme installed and updated. A child theme cannot work on its own, so deleting the parent will break it.
A child theme is the safest way to customize a theme you love. That's all about child themes. If you face any issues while creating one, do let us know in the comment box below.