Minimum files needed for a child theme:
- functions.php
- style.css
- screenshot.png
Minimum code for functions.php:
<?php
/**
* @author Salil Agarwal, WordPress Developer & Consultant
* @author-URL https://blue-cloud.io
* @email salil@blue-cloud.io
*/
add_action('wp_enqueue_scripts', 'bcloud_child_theme_enqueue_styles');
function bcloud_child_theme_enqueue_styles()
{
$parenthandle = 'parent-style'; // This is 'parent-style' for the parent theme.
$theme = wp_get_theme(); // Gets a WP_Theme object for a theme.
wp_enqueue_style(
$parenthandle,
get_template_directory_uri() . 'https://d1ct21abl073ls.cloudfront.net/style.css',
// get_template_directory_uri() Retrieve theme directory URI.
array(), // if the parent theme code has a dependency, copy it to here
$theme->parent()->get('Version')
);
wp_enqueue_style(
'child-style',
get_stylesheet_uri(), //Retrieves the URI of current theme stylesheet.
array($parenthandle),
$theme->get('Version') // this only works if you have Version in the style header
);
}
Minimum code for style.css.
/*
Theme Name: <Parent theme name> Child Theme - <client name>
Theme URI: https://blue-cloud.io
Description: <Parent theme name> Child Theme
Author: Salil Agarwal
Author URI: https://blue-cloud.io
Template: <Parent theme name>
Version: 1.0.2
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Tags: light, dark, two-columns, right-sidebar, responsive-layout, accessibility-ready
Text Domain: <Parent theme name>child
*/
Benefits of using child theme
We should add and use a child theme from the start of the project. This way we do not loose the settings that are saved by theme to the database.