Here’s Why You Should Use Child Themes On Your WordPress Site

You decide to create a new WordPress site. You buy hosting, install WordPress on it and select a theme. The theme almost looks how you want it to, but not quite. You make a few tweaks to the CSS: changes to the typeface and font size, a new color scheme, and perhaps some adjustments to column widths and borders. When everything looks just so, you start publishing content. A couple of weeks go by and you notice that your theme needs updating. After running the update, you’re horrified to discover that all your hard work has been undone. Your site looks exactly the same as it did when you first installed it.

This is, unfortunately, a common story and it’s why, when you edit a WordPress theme, you should always use a child theme.

What Is A Child Theme?

A WordPress theme is a bundle of files. If you look in the theme directory, you’ll see mostly PHP and CSS files. If you edit those files, your theme will change. But, when the theme developer makes changes to the theme and pushes out an update, all the edited files will be overwritten by the new versions. It will be like the changes you made never happened.

Child themes allow your edits to persist through updates. As the name implies, a child theme is a “descendant” of the main theme. Files in the child theme will override files in the parent theme.

Let’s say you want to make some edits to your theme’s style.css file. Instead of editing the style.css in the theme folder, you create a new style.css in the child theme’s folder and import the contents of the old file — you don’t want to start from scratch.

This way, all the original styles will still be used, unless you override them with new styles in the child theme.

To connect your child theme to the parent theme, all you have to do is to add a short snippet of code to the top of the style.css file. The details will be different, depending on your theme, but you can use the following as a template.

Theme Name: My Child Theme
Theme URI: http://mysite.com/
Description: Child theme for my new site
Author: Me
Author URI: http://mysite.com/about/
Template: myparenttheme
Version: 0.1.0
*/

Only the “Theme Name” and the “Template” lines are required. A folder with a style.css file containing the above is all you need for a minimal child theme. WordPress will automatically add the child theme to the theme chooser, and you can activate it as you would any other theme.

If you want to make changes to your theme’s PHP files the same process applies, but in that case you will probably want to copy the contents of the file as well (and you don’t need the boilerplate we just discussed — that’s only for the style.css file).

The only exception to this rule is the functions.php file; copies of that file in child themes do not override the original but are loaded in addition to and before the parent theme’s file, as discussed here.

Matthew Davis is a technical writer and Linux geek for Future Hosting.

Dedicated Server Special

Take advantage of our Double RAM offer on the E3-1230v2 4 x 3.30GHz+HT server! Only $134.95 per month. Managed and Unmanaged options available at checkout.

GET STARTED