How to create a child theme in wordpress?
First create a new folder in your wp-content/themes
directory with a theme name, let’s name it ‘my-child-theme’. Now you have to create a file named
style.css, It is the main absolutely necessary file for a child theme. This style.css file must contain a File Header and the required header fields.
/*
Theme Name: My Child Theme
Author: Author name
Author URI: http://example.com/about/
Description: text goes here..
Version: 1.0.0
Text Domain: my-child-theme
Template: parent theme name
*/
Now you have to load your style.css via wp_enqueue_style()
from functions.php
as shown in this code snippet 1 & 2.
define( 'CHILD_THEME_TEST_CHILD_VERSION', '1.0.0' );
function child_enqueue_styles() {
wp_enqueue_style( 'my-child-theme-css', get_stylesheet_directory_uri() . '/style.css', array('my-theme-css'), CHILD_THEME_TEST_CHILD_VERSION, 'all' );
}
add_action( 'wp_enqueue_scripts', 'child_enqueue_styles', 15 );
add_action( 'wp_enqueue_scripts', 'my_child_theme_enqueue_styles' );
function my_child_theme_enqueue_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}
Once your theme is installed, then go to Themes –> locate your theme –> Click to Activate the child theme.