WordPress: Quick Steps to Setup a Child Theme
WordPress has this neat feature called “Child theme” for a while now. I’m a big fan of this feature. It is important to use this when you are using a theme that you like but want some changes to it. If you work on the theme files directly, chances are you will overwrite the changes when new updates are pushed. I’ve done it before and since the child theme came out I’ve not had any issue with it anymore.
So, here I would show how to setup a child theme quick and easy. Say you are using “twentytwelve” theme as your primary theme. Now you (like me) want to make a change to the header file to add your own code – for example, some Google code to show translation bar. Here are the steps:
1. under your-wp-root/wp-content/themes/ create the directory you want to place the child theme files in
2. now go into your-wp-root/wp-content/themes/your-child-theme/ and create a file named style.css
3. in style.css you will need to put the following piece of comment:
* Theme Name: YOUR CHILD THEME NAME
* Description: Modified 2012 Theme
* Author: Your Name
* Template: twentytwelve
Line 5 is very important here. It tells WP which parent theme directory to use.
4. After the comment you will need to import the parent theme’s stylesheet in. You can either copy paste the entire style.css from twentytwelve directory, or put the following import code:
5. Now you can copy header.php from your-wp-root/wp-content/themes/twentytwelve to your-wp-root/wp-content/themes/your-child-theme/. Make necessary changes to the file and you are good to go.
6. Last step (which you could have done before changing header.php file) is to activate the child theme. In WP admin, under Appearance > Themes look for the theme you’ve just created. Click on “Activate” to use it.
Only the modified files (like header.php) will be used from your child theme’s directory. You can always do these on your local machine, upload the directory via FTP and activate the theme; the steps above are just the way I do it – i.e. login via SSH and do these from command line.
For further reading you can click here.