When you update wordpress active theme, the previous theme folder is replaced with the updated folder and you lose all your changes. But it's also important to update the active theme because it may have security update. Today I want to discuss how to make a child theme to solve this problem.
The Child theme contains:
1. style.css (which will have your modified/added css)
2. function.php (which will have your modified/added codes in function.php)
3. Other custom folders like img(if any)
4. template files that you changed/modified like header.php/footer.php/template_header etc.
the first two files (style.css and function.php) are must!
FIRST OF ALL TAKE A BACKUP OF YOUR THEME FOLDER !!
Create new folder under wp-content --> themes and name it like yourActiveThemesName-child. For example, if your theme is twentyfifteen then the child's name will be, twentyfifteen-child.
So your wp-content --> themes folder will contain, wp-content-->>themes-->> twentyfifteen, twentyfifteen-child
Create style.css under twentyfifteen-child folder. and write the following to your style.css file.
Theme Name: Twenty Fifteen Child
Theme URI: http://example.com/twenty-fifteen-child/
Description: Twenty Fifteen Child Theme
Author: John Doe
Author URI: http://example.com
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Tags: light, dark, two-columns, right-sidebar, responsive-layout, accessibility-ready
Text Domain: twenty-fifteen-child ***/
Notes This code snippet is only for if you are using Twenty Fifteen theme. Please replace the theme name and other things according to your active theme's style.css top.
now please copy all your custom modified/added classes to this style.css file.
Create functions.php under the twentyfifteen-child folder. We need to en-queue the parent and child theme stylesheets.
write the following code to this function.php file.
Notes you need to replace the 'parent-style' with your theme's name carefully.
If you have more than one css file, repeat following line
wp_enqueue_style( $parent_style, get_template_directory_uri() . '/YOUR_STYLESHEET_NAME.css' );
line with your css file.
If you have some custom folders or other modified template files then copy them to your child folder.
Now you are all set. Go to your Dashboard-> Appearence-> Themes
you will see your child theme is there. Activate your child them.
Now you are ready to update your theme. Updating the theme will no longer change your modifications.
For more info:
Child Themes « WordPress Codex
Thats all for today !!