How to make WordPress child theme?

WordPress is open-source software that allows you customization in every possible way. Isn't that great? But you must not implement all the changes you want readily, as it can corrupt your entire website. This is where you need a child theme. This article covers what it is, how it works, and how you can create one. So, read further to understand everything.

Also Note: You need good WordPress Hosting for a smooth process.

What is a child theme?

A child theme is just similar to the parent theme from its backend. But it depends upon the parent themes for proper functioning.

You cannot even activate the child theme if it does not have its parent theme’s support. The part you want to modify in your website is operated by the child theme; the other functions are handled by the parent theme.

Why is a child theme important?

Below are the main advantages of using the child theme:

1: You won’t have to put in the coding effort from scratch. Managing the elements you want to change can be easily tweaked using the child theme.

2: Upgrading your parent theme is possible without losing the child theme customization.

3: Getting back to the old version remains a possibility.

When should you use the child theme?

For making any minor tweaks to your website, you don’t have to get into the hassle of creating a child theme. But if you want to go for a design overhaul or incorporate any major changes in your website, you can create a child theme.

How to set up a child theme?

Before we start with the process of setting up the child theme, let us clarify that it is a bit technical part and you’ll have to follow the instructions closely to get things right. If you are ready, then let’s go:

Create a folder in wp-content/themes:

1: From the c-panel, open My PHP Database.

2: Look for wp-content. Browse your theme folder.

3: Create a new folder in wp-content/themes

You can give any name to this folder. But using the name of the parent theme with "– child" is the best practice. Still, you can name it everything you want.

Create the style sheet:

Once you have created the new folder for your theme, you’ll need a style sheet. A style sheet determines the overall look of your website.

You have to create a .txt file and name it style.css. Don’t forget to add the code from the parent theme. Just open the style.css file from the parent theme, copy the code and paste it into this new file.

Create functions.php file:

In the same folder, create another .txt file and name it as functions.php. In this file, you should add the following code:

<?PHP

//* Code goes here

Yeah, only this code. You just need an opening tag to get going.

If you want a child theme for an experimental purpose, you don’t even need this step. After performing the above task, you’ll be able to activate your child theme. However, it will be all text and no design.

But obviously, if you need a child theme for publishing, you will like it to inherit the style of the parent theme. You can either include the import function or use a line of code in your functions_php file.

Importing the code from the parent theme can slow down the website's performance because the code for the several pages will download simultaneously. This is why you can add the following code at the beginning of the functions.php file to get going:

add_action( 'wp_enqueue_scripts', 'enqueue_parent_styles' );

Function enqueue_parent_styles() {

   wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' );

}

Find your child theme at the WordPress backend:

With the folder and style.css file created, log in to the backend of your dashboard.

1: Navigate to appearance > themes and search for the child theme you just created.

2: Click on activate, and you’ll see it works just like your parent theme.

Now you must be wondering about the purpose of creating the child theme if it had to look just like the parent one. The answer is, you can make all the changes that you want here at this point.

Make changes to your theme:

You can change the color, font, and style of the theme by changing the style sheet. Add custom code in this sheet will override the default setting of the parent theme.

Similarly, changing the other elements of your parent themes is possible. For every setting in the parent theme, WordPress will check for the corresponding file in the child theme folder - if a file with changes exists there, the child theme's settings will be implemented; otherwise, the parent theme's settings will rule. This means that you can copy the files from the parent theme, make changes in them according to your needs, and upload them to your child folder, and you are done.

You can make as many changes as you like without any issues. In case you want the code for a specific function, you can find it online.

Summing up:

As a newbie, setting up the child theme is difficult. But you can do so by following the instructions and using the code from online sources. So, experiment with your existing theme and create a specialized version of your own.


LEAVE A COMMENT

Comment