WordPress Child Theme
Changes you make may be lost when updates to WordPress themes arrive. So if you sub-theme the theme you’re using, these updates won’t affect the image of your site.
You can make Child Theme very easily with the sample codes I will give below.
Step one: Create a folder for the Child theme
In the directory where your site is located (usually in the public_html folder) go to public_html> wp-content> themes folder, right click and create a new folder. Name the folder you created by typing -child after the name of the theme you use. (For example, like online-shop-child.)
Step two: Create a new style.css file
Create a file named style.css in the folder public_html> wp-content> themes> online-shop-child. Add the following codes in it.
/*
Theme Name: Online Shop Child
Theme URI: https://www.acmethemes.com/themes/online-shop
Description: Online Shop Child Theme
Author: acmethemes
Author URI: https://www.acmethemes.com/
Template: online-shop
Version: 1.3.5
Text Domain: online-shop-child
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
The place you will notice here is the Template and Text Domain lines. Template points to the main theme, Text Domain points to the child theme.
Third step: create functions.php file
This file provides advanced customization to your theme.
Create a file named functions.php in the folder public_html> wp-content> themes> online-shop-child. Add the following codes in it.
<?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' );
}
Step four: Enable the Child theme
Go to the WordPress admin panel and click on Appearance> Themes. Activate your new child theme.
Updates coming to your theme can no longer affect changes you make to the theme.