On the weekend of July 21st-22nd, I attended WordCamp Sydney, a gathering of over 200 likeminded people to discuss all things WordPress. This series of posts is an attempt to provide  a brief summary of some of what I learned there. The slide sets for all the presentations are available on Slideshare.

“Child themes are the recommended way of making modifications to a theme.”

WordPress codex.

You should never modify a theme you have downloaded, because if the theme is later updated, you will lose all your changes.

The advantages of using child themes are:

  • Solid framework
  • Upgrades are easier
  • Easier to add features
  • Security – easier to fix bugs
The correct way to make modifications is to create a child theme, in which you put only the things that are changed from the parent theme. You can use child themes to make changes in:
  • Appearance
  • Functionality
  • Favicon
  • Logo / banner
  • Additional components
  • Colour scheme

Even if you are only changing one line of css, put it in a child theme!

How It Works

Stylesheets

The only required file in a child theme is “style.css”.  The start of the style.css of your child theme should look like this:

/*
Theme name: WCSyd Child
Template: wcsyd // name of the parent theme
*/

If you just leave it like this, the “style.css” file of the child them replaces the style.css of the parent theme. So if you only have one line of css in it, then only that line will be applied.

Normally, you wouldn’t want that! You would want to import the styles of the parent theme, and just have the things you want to change in the child theme’s stylesheet. To do this, your child theme style.css would look like this:

/*
Theme name: WCSyd Child
Template: wcsyd // name of the parent theme
@import url("../wcsyd/style.css")
*/

Template Overrides

Any of the WordPress template files can be overridden by placing your revised template in the child theme folder. So if you want your single post page to be different to that in the parent theme, you place the modified single.php file in the child theme folder. This will replace the single.php of the parent theme.

Functions

Unlike the stylesheet and template files, the functions.php file is loaded in addition to the parent theme’s functions.php file. (Specifically, it is loaded right before the parent’s file.)

Geeky Stuff for Theme Developers

How a parent theme is put together has a big impact on how easy it is to use a child theme. If you are building themes, it is good to use these functions:

  • do_action()
  • apply_filters()
  • get_template_part()
  • function_exists()

And it’s good avoid these, as they can’t be overridden in a child theme:

  • require_once()
  • include_once()
  • !important (in your css)
So if you’re looking for a parent theme to use, check the above, as it’s a good guide as to how easy it will be to use a child theme with it.

Other notes

You cannot have grandchild themes!

Some recommended parent themes:

If you can’t / don’t want to write your own theme, there is a plugin that can do it for you – One-Click Child Theme.

You can find the slides from Chris’s presentation on Slideshare.

See also my other WordCamp Sydney notes.