How to create Child theme in WordPress

How to create Child theme in WordPress

Child theme is most important in wordPress. To add more functionality in your theme you need to create child theme, so that functionality don't get affected on updating parents theme. Let's get started and know how to create Child theme....

To add child theme you need two files in child theme folder.

  1. style.css
  2. functions.php

You can add more folder if you want as per you requirements, but these file is necessary because absent of these file WordPress won't treat your child theme as child theme.

Step 1

Log into your website's WordPress Dashboard. Download "WP File manager" plugin to access the files of your WordPress sites.

Screenshot Step 1

Step 2

Now Open the WP file manager. You will see the file structure of your website.

No alt text provided for this image

Now open the "WP-Content" folder and get into themes folder. Here you will get all the themes list which you download.

Create a folder for your child-theme. You can name anything of folder but i would suggest name as parent theme child. for example see the screenshot

No alt text provided for this image

Note: Don't keep space in words while naming the child theme folder or any folder create you in website files.

Step 3

Now it's time to create file inside the child theme folder. Create two files

-- style.css

-- functions.php

Note: Keep the same file name. Don't rename with other name otherwise WordPress won't load it and you will get error of file missing.

No alt text provided for this image

You can add some more folder inside it like "css", "js etc. You can add image for child theme cover image. upload image and name with "screenshot.png".

Now inside "style.css" add some line in comment.


/*

 Theme Name:   Twenty Twenty-one Child
 Theme URI:    http://example.com/twenty-twenty-one-child/
 Description:  Twenty Twenty-one Child Theme
 Author:       John Doe
 Author URI:   http://example.com
 Template:     twentytwentyone
 Version:      1.0.0
 License:      GNU General Public License v2 or later
 License URI:  http://www.gnu.org/licenses/gpl-2.0.html
 Text Domain: twentytwentyonechild


*/        

In this lines of code, you must have to Template name of your parent theme folder name and Text Domain as child.

This tells WordPress basic info about the theme, including the fact that it is a child theme with a particular parent.

Now add some code in "functions.php"

<?php
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
function my_theme_enqueue_styles() {
    $parenthandle = 'parent-style'; 
    $theme = wp_get_theme();
    wp_enqueue_style( $parenthandle, get_template_directory_uri() . '/style.css', 
        array(),  
        $theme->parent()->get('Version')
    );
    wp_enqueue_style( 'child-style', get_stylesheet_uri(),
        array( $parenthandle ),
        $theme->get('Version')
    );
};        

Now activate the child-theme. And start adding custom template and other stuff as per you requirements.

Add those file in "functions.php".

To include file in "functions.php"

require_once 'yourfile.php';        

That's it.

To view or add a comment, sign in

Explore content categories