Friday, April 3, 2020

How to create a child theme the right way

How to install a child theme the right way

Today we will show you how to create a child theme. This is best and the recommended way to make any customization in your theme, although there are few other ways to edit or add some code, this is one of the best practices that experts recommend.

And the main reason is simple. If you modify any file in the theme you’re using you will lose all your work when the theme is updated.

Every time the theme is updated you will have to repeat all the customization. And that’s not a very practical or efficient way to customize WordPress.

If you make your code modification in child theme, it will persist over time and theme updates. Another benefit is that you’ll have only your codes in there, so it’s easier to organize it and find the lines you’re looking for.

So if you want to customize any part of your WordPress installation, here we explain to you how to install these “kids” themes the right way:

1. Create a folder in server

You must have access to server files, navigate through folders into wp-content/themes and create a new folder. Usually it’s called with the same name of parent theme adding -child at the end.

At this time the folder is empty, don’t worry about that, since WordPress is going to keep using files of parent theme even if it’s not activated.

2. Create style.css file

Now get into the parent theme folder and open the style.css file. You must copy the header and paste it into a new file in child theme folder. The one you’ve just created.

This is the header of a style.css of a theme:

Now create a file in child theme folder with the same name of the parent’s name CSS file (usually it’s style.css), paste the header and add the following line at the bottom:

So the style.css file in your child theme should look like this:

Now you can click the save button and exit server, be sure to match template name and import URL line with your parent theme name.

3. Activate child theme

If you go to your WordPress dashboard now you’ll see the child theme in themes page. Activate it, and that’s it.

Now you can add your own CSS styles at the end of the file you’ve already created before. Or also can customize any other file.

To achieve that you must copy any PHP file you want to edit and paste it into your child theme with the same name. Then you can make any changes to the code.

Just be sure to follow exactly the same structure of parent theme when pasting files in child theme folder.

4. Edit functions.php

Many customizations are made by modifying the functions.php file. This is a very important file and it is handled in a different way when working with child themes.

You don’t have to copy and paste the whole file, it will be enough to create a file with the same name -functions.php- in child theme folder and add only the code you want.

How to install a child theme the right way

But, wait. There are some plugins that make things easier.

Yes, that’s right. But I don’t really trust them. I prefer to do it manually.

Handmade is always the best method.

¿What do you think about this?

Seba Rossi
the authorSeba Rossi
Experienced Web Editor with more than 1500 published articles. Passionate about Web development and with advanced knowledge of SEO, amateur guitarist and lover of tasty beer with the company of good and old friends.

Leave a Reply