Child Theme

Child theme is the theme that inherits functionality as well as styling from the parent theme.Child theme is a better way to modify the existing parent theme.
Child themes are separate but have most of the functionalities of the parent theme.Wordpress first checks whether a functionality is present in child theme, if doesn’t it will use the parent theme.
Child theme is a great idea as it can modify and add to the functionality of the parent without modifying it directly.
If we directly modify the theme without creating the child theme, there are two choices:
1) Not opt to update the theme in the future or
2) Update and sacrifice the modifications you have made.
Advantages of using Child Theme:

1) If we are using the existing parent theme as itself and modifying it whenever we need to update the theme, our changes will be lost.
By using child theme, our modifications will preserved.
2) We can speedup Development time.
3) Also the developer can learn basics of WordPress theme development.
4) At any time parent theme acts as a backup (Easy to restore).

Steps to Create a Child Theme:

1) Create child theme folder.
Create a new folder in “/wp-content/themes/” and name it with whatever you like, but the recommended way is to use parenttheme-child” (where “parenttheme”is the name of your parent theme).
For example: If your active theme name is “twentyfifteen” then the new folder created should be “twentyfifteen-child”.

2) Create Child Theme’s style.css File.
Once the child theme folder is created, the one and only required file to be created is a valid child theme style.css.

We need to add some vital information about our theme at the very beginning of the style.css . So open and paste the below code to the blank style.css

Here lot of information is generic and template line corresponds to the directory name of the parent theme.The parent theme in our example is the Twenty Fifteen theme, so the Template will be twentyfifteen as in the above example.

The only required child theme file is style.css.We can also import all style from the parent style.css by using the below single line code

But this is no longer known as a best practice.

3) Enqueue Parent Stylesheet
The correct method of enqueuing the parent theme stylesheet is to use wp_enqueue_script () in our child theme’s functions.php.
So we must create a functions.php file in the child theme directory. After creating the file open php tag (<? php) and after that paste the following code

The above example function will only work if your Parent Theme uses only one main style.css to hold all of the css. If your theme has more than one .css file (eg. ie.css, style.css, main.css) then you will have to make sure to maintain all of the Parent Theme dependencies. Setting ‘parent-style’ as a dependency will ensure that the child theme stylesheet loads after it.

After this the child theme is completely ready for activation.

4) Activating Child Theme
Navigate to Appearance -> Themes in your WordPress admin area. Now we can see the parent theme is active, and should also see your new child theme as below.


and activate it like below.


Then move to view front end,to see the changes.