In this post, I will be showing you how to create a child theme in WordPress

In the previous post, we have discussed child theme we have discussed following things

  • What is a WordPress child theme?
  • Advantages of WordPress child theme
  • Why we should have them

Now it’s time to learn how can you create a child theme.

Before we begin with the steps, take a look at the important note.

Note:-  I will suggest you to create a child theme folder and files on your computer and then copy to your hosting server via FTP or zip the child theme folder and upload it as a theme.

Steps to create a Child Theme

Step 1: Create a folder on your computer and name it as parent theme name hyphen “child”.

Ex:- If My Parent theme is “sydney” then the folder name will be “sydney-child

Step 2: After the folder is created, create two files inside this folder.

  1.  functions.php
  2.  style.css

Step 3: open the style.css file and copy the below code from WordPress.org codex

/*
 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
 Template:     twentyfifteen
 Version:      1.0.0
 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
*/

Step 4: Now edit the Theme URI and template values. Put your theme name instead of  “twenty-fifteen”.

Step 5: Open functions.php file and copy the below code.

<?php
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
function my_theme_enqueue_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}
?>

This will copy the styling from parent theme into a child theme.

Step 6: Now move this folder from your computer to the hosting wp-content/themes folder using FTP.

Step 7: Now it’s time to activate your child theme. Login to your WordPress dashboard and go to Appearance -> theme-> click on activate button for child theme.

Congratulations !! You have created the child theme and you will not lose any code changes due to any updates in parent theme.