Why we need a child theme

Using a child theme allows us to change or update our theme without losing our customizations. Without a child theme, we’d have to edit our theme files directly and any time we updated the theme, our customizations would be lost.

Now that you understand the importance of child theme in WordPress, let’s look at the steps of creating and activating child theme together.

How to create child theme in WordPress step by step

Here our parent theme is Blocksy, but if your theme is Astra or any other theme, the steps are the same.

Step 1: Get Text Domain of the current theme

In the WordPress dashboard, go to the following address:
Appearance -> Theme File Editor

Your active theme Stylesheet file is selected by default, otherwise select your main theme Stylesheet file to display its content.

Edit Stylesheet file in WordPress theme
Edit Stylesheet file in WordPress theme

As you can see in the image above, the Text Domain of parent theme is blocksy, copy this word somewhere because we will need it. (Your Text Domain will vary depending on your active theme)

Step 2: Create child theme files and folder

Create a folder on your computer and rename it to blocksy-child. (Text Domain in step above-child)

Make two text files in the above folder and rename them as follows:
functions.php
style.css

Wordpress child theme files
WordPress child theme files

Open the functions.php with your favorite text editor and copy and paste the following code and save it.

<?php
add_action( 'wp_enqueue_scripts', 'enqueue_parent_styles' );
function enqueue_parent_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' );
}
?>

Open the style.css with your favorite text editor and copy and paste the following code and save it.
* Please change the Theme Name to the name of your choice (chosen name doesn’t matter)
* Please change the Template to your Text Domain in step 1

/*
Theme Name: My Custom blocksy theme
Template: blocksy
*/ 

Your child theme is now ready.

Step 3: Zip the theme folder and install it on your site

zip wordpress child theme
Zip your WordPress child theme

Go to the WordPress dashboard and the Appearance section.
Appearance -> Themes -> Add New

Install Custom Child theme in WordPress

Click on Upload Theme and in the form that appears, use the Choose Files button to upload and install the theme zip file that you created in the previous step. After you see the installation success message, go back to the theme section and activate your uploaded theme.

If this article is difficult for you to read in text, you can watch the video version below.

That’s it, if you have any questions, please ask in the comments section so we can answer.

Is it possible to create a child theme for a WordPress theme that was not downloaded from the official WordPress repository?

Yes, you can create a child theme for any WordPress theme, regardless of its source. As long as the parent theme is properly coded and follows WordPress theme development standards, you can create a child theme by following the same steps outlined in the article. Make sure to use the correct parent theme’s name in the child theme’s style.css file.

Can I create multiple child themes for a single parent theme?

Yes, you can create multiple child themes for a single parent theme. Each child theme should have its own unique folder and style.css file with the appropriate information. This allows you to create multiple variations of your website’s design while still relying on the same parent theme.

How do I update the parent theme without losing the customizations in the child theme?

One of the main advantages of using a child theme is that you can safely update the parent theme without losing your customizations. When updating the parent theme, WordPress will only modify the files within the parent theme’s folder and will not touch the files in the child theme’s folder. Therefore, your customizations in the child theme will remain intact.

However, it’s essential to review the parent theme’s change log and test the updated parent theme with your child theme on a staging site or local environment to ensure compatibility. In some cases, significant changes in the parent theme may require adjustments to your child theme’s code.

Share this post
Maya
Maya

Hi, my name is Maya and I’m a WordPress plugin developer. I created this website to share some of the helpful codes that I’ve used in my own projects.
If you’re looking for a custom plugin for your website, you can contact me by clicking on Hire a developer in the menu. I’d love to hear from you.

Articles: 56

Leave a Reply

Your email address will not be published. Required fields are marked *