After a brief description about how to install WordPress in my previous WordPress tutorial, i am now going to discuss another important topic which is a must when you work on WordPress – WordPress Child Theme
Importance of using a child theme:
You have completely created a website using WordPress themes by modify an existing theme, and your theme gets updated. ??? Ohh gosh!!! Now what?
If your WordPress theme gets updated automatically, all the changes made to your style.css and functions.php page are lost and your theme will be restored back to the original. All you efforts and time are in vain and you will again have to start from scratch. So friends to avoid all this fuss i would suggest you to use a child theme and be stress free.
How to create a Wordpress Child Theme:
1. In your theme folder (wp-content/themes) create a new directory and name it as theme_name-child. Make sure you don’t add a space in the name.
Eg. For twentyfourteen theme, your folder name would be twentyfourteen-child.
2. In the child theme you will have to create a new file called style.css. In this file add the following code
/* Theme Name: Twenty Fourteen Child Theme URI: http://example.com/twenty-fourteen-child/ Description: Twenty Fourteen Child Theme Author: John Doe Author URI: http://example.com Template: twentyfourteen Version: 1.0.0 Tags: light, dark, two-columns, right-sidebar, responsive-layout, accessibility-ready Text Domain: twenty-fourteen-child */ /* =Theme customization starts here -------------------------------------------------------------- */
You can change all the lines, but Template,Theme Name are required.
Template – Directory name of the parent theme.
Eg If the parent theme is the Twenty Fourteen theme, so the Template is twentyfourteen, which is the name of the directory where the Twenty Fourteen theme resides. If you want to make a child of a theme then you would use Template: example-theme-name.
3. As discuss earlier if you do some modification in your theme in the functions.php after which the theme is updates then all your changes are lost. In such case if you want to add custom functions to the theme, you would be required to create a new file called functions.php and here you can write as many functions you wish to. The code structure is very simple.
<?php
//All your code goes here.
?>
Hope this is helpful and speed up your development. Happy Coding folks!