What is a Theme
A theme in WordPress helps us define how our website looks. It consists of a CSS style sheet named styles.css. (This file name must be used.)
At the top of the stylesheet, there will be a CSS comment. WordPress looks at this comment to learn about the theme. It will look something like the following:
/* Theme Name: Access2Learn V2 Theme URI: http://www.waltdesign.com/themes/access2learn Description: My special custom theme I've created Author: Walter Wimberly Author URI: http://www.waltdesign.com Template: Access2Learn Version: 2.0 License: GNU General Public License v2.0 (or later) License URI: http://www.opensource.org/licenses/gpl-license.php */
Additionally there will be one or more PHP files. You can create a theme with a single PHP file, but this is not recommended.
You will normally have an index.php, and then header.php, footer.php, sidebar.php, post.php, and potentially quite a few others.
Why you Need a Child Theme
With the shear number of WordPress themes that you can install (thousands of them if you remember correctly) you would think that you can easily find the theme that matches your needs. However, this is not always the case; especially if you are needing to match your corporate identity.
In cases like these, you are left with two options. You can either:
- Build your own theme from scratch, or
- Create a child theme.
But why not just modify the main theme? Well you can update a theme. If you had a theme that was updated, then it would over write all of your changes. Now you would not have your theme, but someone else’s theme.
If you create a child theme, and the parent theme gets updated, it doesn’t effect your theme, so you keep working normally – as long as they don’t change the classes assigned to certain elements, but that is a different story.
What is a Child Theme
A child theme resides on a WordPress server which has the parent theme installed on the server. Then you create a new theme, and specify that it is a child of the parent theme.
When you do this, WordPress looks at the two themes. If a file doesn’t exist in the child, it goes and pulls the parent theme’s file. On the other hand, if the file exists in the child theme, it is used instead of the parent’s file. This is how you can modify the existing parent theme to make it your own.
In my experience, I’ve built child themes that only modified the CSS, because the theme was almost what I needed, but it needed a tweak to the layout. Access2Learn is like that for the most part. In other cases, I’ve found I need to tweak several files.
With a child theme, you will also need to import another theme’s CSS. This is how WordPress knows it is a child. This is done inside your CSS, even if it is the only CSS you use.
/* Import Genesis so this is a child theme */ @import url("../genesis/style.css");
When I create a child theme, I make sure I designate it as such inside the top comment header of the style.css file, to make sure I don’t accidentally delete the parent theme from WordPress – which would break my child theme.
/* Theme Name: Access2Learn V2 Theme URI: http://www.waltdesign.com/themes/access2learn Description: Child theme for Genesis Author: Walter Wimberly Author URI: http://www.waltdesign.com Template: genesis Version: 2.0 License: GNU General Public License v2.0 (or later) License URI: http://www.opensource.org/licenses/gpl-license.php */
Understanding Child Themes in WordPress was originally found on Access 2 Learn