How to create a WordPress child theme

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?

Child theme items

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:

  1. Open the theme directory on your server
  2. We recommend using an FTP client like FileZilla to connect to your server and deal with files.

  3. Navigate to /wp-content/themes/
  4. Create a new folder and name it whatever you like
  5. 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’.

  6. In your newly created folder, create the only file you will need – style.css
  7. That is the file which will take priority over the parent one and load information you have provided within the file.

  8. Open the style.css file and paste the following code:
  9. /*
    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
    */
  10. You should modify the information and enter your name, URL, etc.
  11. Important: template should have a correct name of your current theme.

  12. 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:
  13. @import url("../parenttheme/style.css");
    

    Of course, change the ‘parenttheme’ part to name of your parent theme’s folder.

  14. Save everything and you’re ready to activate the child theme
  15. Go to Appearance -> Themes
  16. 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.

  17. Click activate and that’s it!

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.

START YOUR OWN BLOG

This guide is an introduction to mastering the art of blogging. It provides easy to follow steps to start, maintain, and grow your blog.

Read the guide

One thought on “How to create a WordPress child theme

  1. […] it is not even difficult to create a child theme in WordPress. Everything you will need to create such a theme in your WordPress is just one line in your new […]

Leave a Reply

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