A child theme inherits the styles and functionality of another existing theme which becomes the parent theme. Child themes are the best way to modify an existing theme.
This WordPress tutorial lets us learn about creating a child theme template with an example.
Following are the reasons to use a WordPress Child Theme:
That’s it! you are ready with your minimal WordPress Child theme. Child theme should be put under theme directory and activated as usual.
Child theme’s style.css should start with a standard comment. You can use the following as a template.
/*
Theme Name: Foo Bar Child
Theme URI: http://example.com/foo-bar-child/
Description: Foo Bar WordPress Child Theme
Author: Vincy
Author URI: https://phppot.com
Template: foobar
Version: 1.0.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Tags: light, two-columns, right-sidebar, responsive-layout
Text Domain: foo-bar-child
*/
Template
is the directory name of the parent theme.Create a file named functions.php
in the child theme folder and add the following script to it. This is to enqueue the parent theme’s stylesheet.
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}
Above template, the script assumes that your parent theme has one stylesheet name style.css if you have more change this script accordingly.
functions.php
from Child Theme is loaded in addition to the parent theme’s functions.php. The order of loading is, child theme’s functions.php is loaded first, and then the parent theme’s functions.php is loaded next.