Due to the nature of code it is very difficult to support a product if you modify its core code. Luckily WordPress has a feature which allows you to modify a theme without actually modifying its files. This method is called a child theme and here is how it works.

Child themes are essentially separate themes which are based on another theme. The most basic child theme is 100% based on its parent theme, meaning it looks and functions the same way. When creating a child theme you always use all the files of the parent theme, except where specified otherwise. Let’s make this clear with an example.

Let's say you bought Rock Band and you want to modify the post date display on date flag layout posts. The file which handles this is layouts/post-dateflag.php. You could just go into this file and modify it. It would work fine. However, when you update your theme you will loose all your changes.

Instead of doing that, you should create a new theme called My Rock Band for example. This theme will have no files in it, except for the ones which you change, in our case the post layout file.

When you update Rock Band, your child theme – My Rock Band – will use the new versions of all the files but it will continue using your version of the post list layout.

Step By Step

To create a child theme first create a new folder named my_rockband in the themes directory. Create a style.css file and add the following as the content.

/*
Theme Name:     My Rock Band
Theme URI:      http://myrockband.com/
Description:    My child theme based on Rock Band 
Author:         Mr. Awesome
Author URI:     http://yourdomain.com/aboutme/
Template:       rockband
Version:        1.0
*/

@import url("../rockband/style.css");

There are two key pieces of data in there. The most important one is the Template: rockband. This tells WordPress which theme you want the parent to be. This should be the directory name of the theme you chose.

The other important line (although not actually required) is the @import. This loads all the styles from the parent theme.

That is it, you now have a child theme which is a copy of its parent.

Customizing Child Themes

Once you’ve created a child theme you will want to customize either functionality or design. If you just want some CSS changes you can do that in the style.less file after the import.

If you need to change how the theme works you will need to create a copy of the files and modify them. Going back to our album list example, the easiest way to modify it is to do the following:

  1. Create a layouts directory
  2. Create a post-dateflag.php file in the new directory
  3. Copy paste the code from the original file into the new file
  4. Modify the new file

Further Reading

That’s most of what you need to know, but if you need some more help, or you would like to learn more about the topic, the WordPress Codex has a great Child Themes article.