Tuesday, December 10, 2013

How important is it to work with Child Theme in Wordpress

 When I purchased the domain and hosting, the first thing that I did was to install Wordpress and was in a hurry to bring it live with my first post. But did many mistakes and one among them is not having Child theme in Wordpress. Note that here i'm speaking about Wordpress.org installed your hosting server and not Wordpress.com.


Also check: How to fix wp-config corrupt file issue in WordPress


I went ahead and installed the free theme Montezuma and happily continued writing my first post. Did a lot of modification to this theme by modifying the existing code and added few lines of code on my own. After few months I got an alert saying there is a new version of this theme. I usually get such notifications for plugins and I just look into what the changes are in the new version before installing. Theme updates are not very frequent like how we get updates for plugins. I just clicked on update and was happy that I had the latest updates installed.


Also check: How to manually disable WordPress plugin


To my surprise, I was taken back to my original theme like the one that I initially had when I just installed Wordpress and the theme. All the code modification and customization were gone. The simple reason is I did all the customization on the original parent theme and did not create any child theme in Wordpress. Had to do all the coding again. It's always better to take a backup of all the files before you upgrade your blog or website core files so that if something goes wrong with the change, then you can always go back to the original settings using the backup files.


how to create child theme in wordpress


Consider creating a child theme in Wordpress to be a mandatory stuff to do even though it is not, to avoid a situation like mine. By creating a child theme it inherits the functionality of it's parent theme. It's always easier and safer to modify an existing theme. To create a child theme in Wordpress all that you need to do is as shown above in the hosting server under wp-content >> themes folder create a new folder with the same name as parent theme followed by "-child". Within this folder create a new file named as 'index' with file extension as .php. And this index.php file should have the following code (for 2013 theme as an example):


Also check: How to backup WordPress Website and Data



/*
Theme Name: Twenty Thirteen Child
Theme URI: http://example.com/twenty-thirteen-child/
Description: Twenty Thirteen Child Theme
Author: How To Tech Guru
Author URI: http://howtotechguru.com
Template: twentythirteen
Version: 1.0.0
*/

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

/* =Theme customization starts here
-------------------------------------------------------------- */

Save the file and activate this theme on your Wordpress dashboard >> Themes . You can modify the above the code,  the only required lines are the theme name and the template.


Also check: How to protect WordPress wp-config file


Having a child them will always help and the few reasons are:




  • You can always play around with the child theme and it's code more like a test environment.

  • If you modify the original theme by updating it's code then any changes will be lost when you upgrade your theme. If you have a child theme then you just need to upgrade the parent theme.

  • It can speed up development time.

  • When you upgrade the parent theme, you get all the updates even when you are using child theme because the child theme's styles will override those of parent theme's stylesheet.


Also check: Must have WordPress Security plugin for a website

All changes to your website footer, header, theme, fonts, color or any code modification should be done in child theme by creating these files (copy of files that are present in parent theme) inside child theme folder. So, when the parent theme is upgraded your child theme is not updated but you still get all the updates from parent's theme.


If you like this post then don’t forget to share it with your friends and follow us on Social Media or subscribe to our blog via email.

No comments:

Post a Comment