In this article I will show you how simple it is to create child theme for your WordPress website and also i show you some of the things that are needed if you’re doing so too.
But first let’s understand
What Is a WordPress Child Theme
A WordPress child theme inherits the look and feel of the parent theme and all of its functions, but can be used to make modifications. It is a good way to customize your website without having to modify the parent theme.
Child themes are great because they help keep all of your changes isolated from parent theme.
What you need for creating child theme?
A basic knowledge of CSS/HTML is essential, so you can make your own changes. Some knowledge of PHP would definitely help. If you are good at copying and pasting code snippets from other sources, that will work too.
If you have FTP or cPanel it would be great, but if you don’t know how to use FTP or file manager in cPanel I will show you one easy way to doing this work
1) Go to Add New Plugin In your WordPress dashboard.
2) Search for “File manager” and install very first you see
3) After complete installation you will see file manager option in your WordPress dashboard. Click on File manager And go to theme folder inside wp-content folder.
4) Now Right click in themes folder and create new folder for your child theme. You can name this folder anything you want. For our example I’m naming the “demochild”
5) In the folder for your new theme, create a file called style.css. And Add the following code to it:
/*
Theme Name: My Child Theme Twenty Twenty One.
Theme URI: https://zypacinfotech.com/
Description: My First Child theme From Zypac.
Author: Zypac
Author URI: https://zypacinfotech.com/
Template: twentytwentyone
Version: 1.0
*/
@import url("../twentytwentyone/style.css");
Change all the values accordingly. The most important field is Template because it tells WordPress which parent theme your child theme is based on. Once done, click Save and Close.
This is the minimum requirement for creating a child theme. You can now go to Appearance » Themes where you will see WPB Child Theme. You need to click on activate button to start using the child theme on your site.
The Functions File
Adding code snippets to the functions of the parent theme is not good for us because whenever there is a new update for the parent theme, all our changes will be overwritten. This is why it is recommended to always use a child theme and add all your custom code snippets to the child theme’s functions.php file.
For this create new file in your child theme’s folder and name it functions.php.
<?php
/* enqueue script for parent theme stylesheeet */
function childtheme_parent_styles() {
// enqueue style
wp_enqueue_style( 'parent', get_template_directory_uri().'/style.css' );
}
add_action( 'wp_enqueue_scripts', 'childtheme_parent_styles');
In first step we add parent theme css to child theme using @import command in style.css. We do not recommend this method as it will increase the time it takes to load the style sheet.
We recommend to create a function.php file in child theme and use wp enqueue function to load parent theme css.
I hope this article helps you get started. Thanks for reading