Tags

, , , ,

wordpress-child-themes (1)What is a Child theme?

I would simply say a “child theme” is something which keeps your changes in the theme intact even when the parent theme is updated. A child theme inherits the functionality of the parent theme, and allows you to modify, or add to or get rid off, the functionality of the parent theme.

A child theme is the safest and easiest way to modify an existing theme, whether you want to make a few tiny changes or extensive changes.

A child theme inherits all of the templates and functionality from its parent theme, but allows you to make changes to the parent theme because code in the child theme overwrites code in the parent theme.

Why would I use child theme?

To justify the need of using child theme, I would give you an example, just think of a situation where you have been working very hard to customize the need of your client in a theme the whole week and finally finishes it off on a Friday to have a great weekend.

But even before you have planned your weekend your client says he wants to upgrade the theme to the latest version as it contains some newest features that he would love to have. What do you do now? Scratch your head, bang it on the wall next to you and stay the night to point out the changes you have made, make a note of them, upgrade the theme and put the customized features back and even you do this with utmost carefulness there is a possibility you might have missed something.

In the contrary if you would have used a child theme, you would have asked your client to go ahead with the up-gradation and would have also wished a “Happy Weekend”, yes because the child theme would keep the customizations intact even when the parent theme is upgraded/updated.
So using a child theme is always a win win for the developers.

How to create a child theme?

To create a child theme one has to create a directory for the child theme in the wp-content/themes directory. You can name it anything you want but I prefer to name it with a term “child” appended to the parent theme. For example if we are creating a child theme for twentytwelve WordPress theme then I would name the child theme directory as twentytwelve-child.

To make a child theme up and running the only required file is style.css. You need to add the file to the child theme folder with the following header.

/**
 * Theme Name:     Twenty Twelve Child
 * Theme URI:      http://www.mindfiresolutions.com/
 * Description:    Child theme for the Twenty Twelve theme
 * Author:         Maruti Mohanty
 * Author URI:     http://www.mindfiresolutions.com/
 * Template:       twentytwelve
 * Version:        1.0
 */

From the above the only required things are “Theme Name” and “Template”.
Theme name can be anything of your choice and the Template would be the same name as the directory name of the parent theme. Here I am using the Twenty Tweleve theme for the example whose directory name is twentytwelve.
For anything other than this two is optional and completely depends on individual.

The child theme’s stylesheet will overwrite the parent theme’s stylesheet, but chances are you want to include the parent theme’s stylesheet. To do this, you need to start the stylesheet with the following line:

@import url("../twentytwelve/style.css")

Replace twentytwelve with the directory name of your parent theme. This line must go after the header code and before any other CSS rules. If you put other CSS rules before the @import, it will not work.

You can activate the child theme by logging in to your site’s dashboard, and go to Administration Panels > Appearance > Themes. You will see your child theme listed there. Click Activate.

If you miss a theme image in the manage theme options, you can add a preferred image to the child theme directory and name it as screenshot and it would appear in the themes.

What we can modify using a child theme?

Through the child theme’s functions.php file we can deal with:

  • Theme features
  • Custom post types and taxonomies
  • Menus and sidebars
  • Widgets
  • Shortcodes
  • Additional image sizes
  • Metaboxes
  • JavaScript and CSS
  • Parent theme actions and filters

So now its time to try child theming.

Reference:WordPress Codex for Child theme

About these ads