What is child theme
Are you aware about there is something called child theme in WordPress?
Have you ever learned what is child theme?
Child theme, get all the functionality, style and features from parent theme.
Child theme is an equal concept of Inheritance.
Inheritance means Class B can derive from class A with existing features and also including own new features.
The main benefit to child theme is you cannot loss your data after WordPress or any plugin updates.
Child theme load faster than parent theme, so plus point bit faster then parent theme.
We can use child theme to modify style and functionality without affecting an parent theme.
Child theme is very easy to create we discuss also in this article how to create and use.
Problem: I use directly parent theme for my E-commerce Website
Once I have working on parent theme in my local system. I have formatted more than one page and styles for E-commerce website.
more than one functionality I have created in functions.php file, that time I don’t know about child theme, but aware of WordPress Updates, like you can up to date with themes and plugins so chances of hacking and DDOS attack are being least chance.
So I can update the WordPress themes without backup data, after I update I can refresh my website, all functionality data will be lost because, when you are updating WordPress theme, they are noticed before you update theme you show the notice like must backup, Functionality like custom created templates, styles, database tables. Because some time we loss the data and function file will be lost then we custom data added.
I search on this topic for child theme and working on it. Let’s start how to create child theme
How to use child theme?
You can easily create child theme with create style.css in child theme folder so let’s start
Go to the directory like this
your-project-name\wp-content\themes
here we can create child theme of twentytwenty theme
Inside this themes directory create directory (or folder) whatever you want name like below image
I create twentytwentychildtheme name directory
Inside directory
your-project-name\wp-content\themes\twentytwentychildtheme
create style.css inside your-project-name\wp-content\themes\twentytwentychildtheme\style.css
like below image
paste below code in style.css
style.css
/*
Theme Name: twentytwentychildtheme //whatever you want but best practice you can use this directory name
Theme URL: http://yourdomain.com //paste your parent URL
Description: Twenty Seventeen Child //theme description
Theme Author: Your Name //theme author name
Author URL: http://yourdomain.com //author URI
Template: twentytwenty //parent theme directory name
Version: 1.0.0
Text Domain: twentytwentychildtheme //enter your current directory name
*/
Your file is look like below image
save and go to WordPress/appearance/themes
here you can see you created custom child theme are shown
Simply clicked on activate the theme and view your site like below image
This is not look good but don’t worry I help you to get parent theme style functionality.
create functions.php inside child theme.
your-project-name\wp-content\themes\twentytwentychildtheme/functions.php
Function.php
<?php
add_action( 'wp_enqueue_scripts', 'enqueue_parent_styles' );
function enqueue_parent_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' );
}
simply this code can call parent style.css and now look your site an normal theme, refresh previous page and look like below image
now you want to work on child theme as you want.
Conclusion
Child theme is an safe and powerful technique to derived parent theme functionality and style etc., also child theme is load fast compare to the parent theme.
We are not expert but this article we created based experience on owner of this website.
Generally we say’s must be aware for security. Updates themes and plugin with latest updates don’t wait for it because security is very important.
If this article found you useful share it to those who are in need of this.
Sharing is caring.
Also Read
How to secure WordPress website?
Best SEO tool for WordPress
Difference between login and sign in