What is a WordPress child theme? Tutorial to create a child theme
Last updated:
In WordPress, when you customize an existing theme, it is recommended to create a child theme. This article explains what a child theme is and how to create one, even for beginners.
What is a child theme?
A child theme is a theme that inherits the features and style of the parent theme. When editing an existing theme, it is recommended to create a child theme.
Why create a child theme?
If you change the theme directly, your edits will be lost when the theme is updated.
There is also the option of not updating the edited theme, but we do not recommend this for security reasons.
Child themes allow you to describe what you want to edit, so that your edits will not be lost when you update the parent theme.
Parent Theme vs Child Theme
The parent theme is the original theme that you want to customize. It is a free theme installed from the official directory or a purchased paid theme.
Please see the next article for more information on the theme.
What is WordPress Theme? Summary of how to choose and use a theme
Child themes can only be created when you have a parent theme. As the name suggests, you have a parent-child relationship.
A child theme inherits the functionality and style of the parent theme, and you can customize only what you want to edit.
If the functionality of the parent theme is upgraded, the child themes will be able to use the same functionality.
How to create a child theme
Step-by-step instructions on how to create a child theme.
Create a folder
First, use FTP software to create a folder named “parent-theme-child” under the “~/wp-content/themes” directory on the server.
For example, if you want to create a Twenty Twenty child theme, the name of the folder would be “twentytwenty-child”.
The folder name of the child theme must not contain spaces. You will get an error.
Prepare the file
Prepare the following two files, write the necessary code and store them in the child theme folder.
- style.css
- functions.php
style.css
At a minimum, style.css should contain the following.
/*
Theme Name: The name of the child theme
Template: Parent theme folder name
*/
The Template is the name of the parent theme’s folder; for Twenty Twenty, it’s “twentytwenty”.
Add the style you want to edit after the comment.
functions.php
In functions.php, you need to include the following code.
<?php
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', array('parent-style'));
}
?>
The location of the style.css for the parent theme and the child theme. That’s it, you’re ready to enable the child theme.
Activate a Child Theme
Log in to the WordPress admin page. For more information on how to log in, please refer to the following article.
How to Login to the WordPress Admin Screen
- Move the mouse pointer over the Appearance
- Click on the Theme
Press the Activate button for the child theme you created.
The child theme has been activated.
Deleting a Child Theme
Child themes cannot be removed from the administration screen if they are enabled. Activate another theme.
Click on the Theme Details of the child theme.
Click Delete to remove the child theme.
If the child theme is not reflected
As mentioned in the “How to create a child theme” section of this article, you will need the following two files in the child theme folder.
- style.css
- functions.php
Also, you need to activate the theme to reflect the content of the child theme. Please refer to “Activate a Child Theme” in this article.