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.

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”.

Child theme folders

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

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.

Theme

Press the Activate button for the child theme you created.

Child Theme Activate

The child theme has been activated.

Active child theme

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.

Theme Details

Click Delete to remove the child theme.

Delete 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.

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.

Most Popular Articles

  1. Vulnerability of File Manager WordPress plugin and Solutions
  2. What’s new in WordPress 5.5? New Features and Changes
  3. How to use the current_user_can function in WordPress
  4. What is WordPress’ server requirement? Support for Each Version
  5. What is WordPress? Guide for beginners
  6. How to check if the current user is Administrator in WordPress
  7. WordPress Version List (Release Date/Code Name)
  8. What’s new in WordPress 5.5.1? 44 bugs fixed

New Articles

go to top