How to create a simple WordPress Child Theme

This post is over 3 years old, so please keep in mind that some of its content might not be relevant anymore.

There is a right and wrong way of editing a WordPress theme. If you modify the original one, every time there is an update all your changes will be lost. Yes, you guessed it. This is the wrong way!
Since WordPress 3.0 child themes are extremely easy to implement.

What are child themes?
As WordPress.org states: “A WordPress child theme is a theme that inherits the functionality of another theme, called the parent theme, and allows you to modify, or add to, the functionality of that parent theme.”
It couldn’t have been clearer than that..

How you create child themes
Let’s say we want to modify the default theme called “twentyten” that is in “wp-content/themes/”.
In the same folder “themes” we have to create another folder for the new theme.
We can call it whatever we want. I’m going to call it “my-twentyten”.
Now, to make the new theme working, we need only a file called “style.css” with a basic content like the following to link the child with the parent theme:

/*
Theme Name:     My Twenty Ten Child
Theme URI:      http://www.opensourceisbetter.com/
Description:    Child theme for the Twenty Ten theme
Author:         Andrea
Template:       twentyten
*/

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

The “Theme Name” and “Template” tags are the only required. The first is just to recognize the theme, the second is to define the parent theme.
The last line imports the CSS style from the parent theme. It’s absolutely not mandatory. If you prefer you can omit that and re-create all CSS from scratch..

NB: If you want to overwrite any other file in the theme folder (eg: footer.php, header.php etc..) simply add that file in the child theme and change it as you wish.

How to enable the new child theme
You enable a child theme exactly like you would enable any other theme!
You go in the WordPress admin panel and you activate it.
(eg: In the Twenty Ten theme; Appearance -> Themes and then you can activate your theme.)
No more template customization overwritten by updates!!!

Enjoy

Leave a Reply

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