by Maruti Mohanty · Published July 5, 2015 · Last modified August 12, 2015
Child theme is a topic which has been talked, discussed and written a lot and yet is very important for every WordPress Developer. I personally believe child theme is one of the many awesome features which makes wordpress what it is today.
Child theme can be basically defined as a theme which derived it features from a parent theme and allow the user to override the features/design from the parent theme which would remain conserved even after updates.
Child theme is one of my best practice for wordpress development, it becomes more essential for the user who uses a theme may it be free or premium and tend to customize it to make it match his/her needs and requirement.
Why to use child theme?
Because a user, however simple he wants his site to be, tends to make some changes and customizations to the theme, may it be a change in color, font size or image sizes and Updating wordpress, its plugins and themes are inevitable because everyone wants a better product.
If you do not use a child theme, you tend to loose all the changes made to the theme once you update your theme. But child theme can save you from this. So It is highly advisable to make a child theme of your parent theme and keep the customizations to the child theme.
Where to use child theme?
Child theme should be used in all wordpress projects which uses a theme which is not built from scratch for that respective project, which means if you are using a free theme from wordpress.org or any premium theme.
How to use child theme?
Creating a child theme is super easy. 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: sourcexpress
* Theme URI: http://www.sourcexpress.com/
* Description: Hueman Child Theme
* Author: Maruti Mohanty
* Author URI: http://www.sourcexpress.com/
* Template: hueman
* Version: 1.0.0
Though the only required line was Template: twentytwelve, other add more details to the header.
After this add the below code to import the style.css of the parent theme
Once this is done you can move the child theme folder to the themes folder and the theme would appear in the Appearance > Themes. You will see your child theme listed there. Click Activate.
Once activated, the changes made to the child theme would reflect in the front end.
Using child themes you can also override the parent theme’s files like header.php, single.php etc.
To override the template files you need to copy the file to the child theme folder and make the changes to it and then save it. But the files which are in located in further sub folder, the customization of those files depends upon the child theme compatibility of the parent theme.
Template file like functions.php behave a little differently. Instead of overriding the parent theme’s functions.php, the child theme’s functions.php file loads prior to that. so both the functions.php file loads.
So Child theme is not only a good wordpress development practice but also a faster way of developing a site without the swords namely “updates” dangling over your heads(read customizations).