Once you start to develop your own theme or maybe modify an existing one, you will learn there are thousands lines of code distributed among many files. At the beginning, it will seem easy to simply overwrite the existing code, and it is, but it’s definitely a wrong way to go.
If you overwrite the code, you will have a hard time updating your theme in the future. It might be a few months before your theme gets an update, and once you choose to install one, the theme will again overwrite every modification you have done so far. On the other hand, if you choose not to update your theme, you will take a huge risk of getting errors, some plugins might stop working and you’ll become an easy target on a hacker’s crosshair.
That’s where a child theme comes in to save you. Once you create a child theme, every modification you create will be stored in a special file which is connected to your main, parent theme. And how does that work, you might ask?
After your site loads a theme, it will first check a child theme. If WordPress finds something in the child theme, that functionality will be loaded while the main one will be neglected. But, if the functionality hasn’t been found, WordPress would call it from the parent theme and everything would work as normal. It’s easy as that.
And because now you are working with a separate file, you are free to update your theme whenever you need to and your child theme will be intact.
Create a child theme:
- Open the theme directory on your server
- Navigate to /wp-content/themes/
- Create a new folder and name it whatever you like
- In your newly created folder, create the only file you will need – style.css
- Open the style.css file and paste the following code:
- You should modify the information and enter your name, URL, etc.
- To make everything work, you will have to call your parent theme into the file. You can do that simply by adding the next piece of code to your style.css:
- Save everything and you’re ready to activate the child theme
- Go to Appearance -> Themes
- Click activate and that’s it!
We recommend using an FTP client like FileZilla to connect to your server and deal with files.
It is considered as best practice to name the folder as your theme’s child. For example, if you’re creating a child for a Permatex theme, you might want to name it ‘permatex-child’.
That is the file which will take priority over the parent one and load information you have provided within the file.
/* Theme Name: My Child Theme Theme URI: http: //mysite.com/ Description: This is a custom child theme. Author: Name Author URI: http: //mysite.com/ Template: parenttheme Version: 0.1 */
Important: template should have a correct name of your current theme.
Of course, change the ‘parenttheme’ part to name of your parent theme’s folder.
Here you will notice that your parent theme is still active. Underneath you should find your child theme with the information provided in the style.css file.
Of course, unless you have added changes to the newly created file, you won’t be noticing any changes. All you have to do is add style changes to your new style.css file and those will be shown on the website.
So far, you have created a file which can do changes for the website styling. But what if you want to change a theme’s functionality and PHP code? As you might have guessed, all you have to do is copy and paste file you want into your child theme’s folder.
For example, if you want to add the extra piece of code to your functions.php file, you should copy and paste the original file from the parent theme into your child theme folder and edit it from there. That’s it! You can do the same for every file you find in the parent theme without worrying you will mess up your entire site.
If you want to make things even simpler, in our future articles, we’re about to show you how to create a child theme by using a plugin.