Using a child theme to avoid problems with updates

Many of the articles on the DIY Blogger show how to “tweak” the theme files in order to make small changes to the appearance of a site, such as making the header clickable or changing the menu colours.

These theme files, including the style sheet, are located in a sub-directory of /wp-content/themes/, but there is a problem.

Many modern themes such as TwentyTen release updates and when these get installed it overwrites the changes as well, effectively reverting the design back to its original state.

The answer is a “child theme”.

A child theme is actually quite simple to set up, but it is often overlooked.  Basically, it is a special type of theme that only includes the changes to the main theme.  In some cases, you replace entire files, and in others you just add to existing ones.

To set up the child theme, create a new sub-directory on your server with the same name as the main theme followed by a hyphen and then “child.”  So you might call it “twentyten-child”.

The simplest thing to do now is to copy any files that you have modified from your original theme into this directory, and then activate it in the WordPress administration menu (under “Appearance”).   That way, when the files in the original directory get overwritten by an update, only the files that you have not changed will take effect.

However the child theme is more sophisticated than that, as you do no not need to copy the entire style.css and function.php files.

Instead these files get appended onto the main theme files, so you can start off with empty versions and just add any changes that you want made.

In the case of the menu colours you would only re-define the colour elements that need changing, and not the entire menu element, making it much clearer if you want to re-use the theme later which parts were modified and which were not.

For example:

#access li:hover > a,
#access ul ul :hover > a {
background:#77a;
}

About Graham Tappenden

Graham Tappenden is a blogger from Germany. He has written code for WordPress themes since 2006 and been creating websites since 1994.
This entry was posted in Theme Basics and tagged , , . Bookmark the permalink.