So you want to make changes to the code of your WordPress theme?
Maybe you just want to make a few styling tweaks, or perhaps you want to completely change the layout of the page templates. Maybe you want to create your own page templates, or set up custom post types.
That’s great! But before you get started, you need to set up a child theme and use this instead of your existing theme. Don’t go straight in and edit the code of your existing theme because it’s going to cause you problems later down the line.
Why will it cause problems? Well, allow me to explain.
In this post I’m going to explain why you shouldn’t edit the code of your WordPress theme directly, and why you should use a child theme instead.
Why shouldn’t I edit the code of my WordPress theme directly?
So, you’ve decided that you want to make some changes to the code that makes up your website.
Ok, that’s fine. But what happens when the theme author pushes out an update? What will happen to the changes that you’ve made to the code?
Well, they will disappear! When a theme is updated, the files that make up that theme are replaced with the new updated files. Therefore, any changes that you made to those theme files will be lost.
So I shouldn’t update the theme?
You might be thinking “I just won’t update the theme then”. Well, yes, that would protect your changes from being lost, but I strongly advise again not updating your theme.
Theme developers update themes for a whole variety of reasons. It might be to fix bugs, to make it compatible with core WordPress updates (such as when WordPress 5.0 was released, for example), to make it compatible with popular plugins, to resolve potential security issues, etc.
Not updating your theme means that you won’t have updates to these new features and this might lead to problems later down the line. For instance, when the new editor was released with the WordPress 5.0 update, many themes had to be updated to ensure that they worked with the new block system.
How do I make changes to my theme then?
If you do want to make changes to your theme’s code then it is best practice to set up something called a child theme.
What is a child theme?
A child theme is a theme that inherits the styling and functionality of another theme known as the “parent theme”.
So ultimately the child theme looks and functions in exactly the same way as the parent theme, but you can change the code of the child theme without affecting the parent theme at all.
I like to think of it like the child theme piggybacks off the parent theme!
The changes you make in the child theme files work in conjunction with or override the files of the parent theme.
How do I create a child theme?
There are two ways to create a child theme; using a plugin or manually.
Using a plugin
If you aren’t confident with editing your website files or if you aren’t sure how to access your website files, it might be best if you a plugin to create your child theme.
I recommend using a plugin called Child Theme Configurator. It’s free and simple to use with no coding involved!
If you would like to learn how to set up a child theme using the Child Theme Configurator plugin then check out this tutorial.
If you are confident with editing your website files and editing code then you might want to set up your child theme manually.
Setting up a child theme manually involves creating all the relevant folders and files that are required and using code to link your child theme to it’s parent theme.
Again, if you’re interested in learning how to set up child themes manually then I recommend checking out this tutorial.
But I’ve already made changes to an existing WordPress theme?!
If you’re reading this post and thinking “Help! I’ve already made changes to my theme’s files!”. then don’t worry!
What you need to do is create a child theme, either manually or using a plugin, and then copy across the changes that you made to the main theme over to your child theme. Then you can activate your new child theme, and if all has gone to plan it will look exactly the same as it did before!
Don’t update your theme until you have created a child theme and copied across your changes or else you will lose your changes!
Does this apply to custom-built themes as well?
If you have had a WordPress theme built specifically for you then editing the main theme files directly shouldn’t be a problem and you shouldn’t need to create a child theme. However, if you aren’t sure, speak to the developer who built your website and ask them what they recommend.
In some situations, your developer might have already set up a child theme for your custom-built theme ready for you to edit. Again, if you aren’t sure, just ask.
Personally, if I were in this situation I would create a child theme anyway. Why? Because if you start editing the code of your theme and something goes wrong, the person who developed your theme in the first place might charge you to fix the issue.
If you set up and use a child theme for your custom built theme and then something goes wrong, you can simply switch back to the original theme.
Hot off the WordPress!
Join my FREE email community today to receive helpful tips and advice on building and maintaining your website directly in your inbox every other Friday. Just pop in your name and email address.