Creation of a Child Theme for your WordPress Website
Child theme
It is a complete theme which includes all of the essential required WordPress template files and assets for the theme to work. Importantly need to mention all themes doesn’t include child themes are considered parent themes.
A child theme uses to modify small aspects of website’s appearance by keeping the original theme’s look and functionality. To know how child themes work first things is the relationship between parent and child theme.
Parent theme
When any modification done on child theme will not affect the original or parent theme. But if the parent theme makes any changes it will be visible in the child theme.
Advantages of Child theme
- It slower down development time.
- modifications portable and replicable
- No need to create complete theme rather the customization of parent theme is easy.
- It allows parent themes to be updated without losing added modifications.
- It is a great way to start learning about theme development.
How To set Up a WordPress Child Theme
It can be set up in two ways.
- Creating a Child Theme Manually
- Creating a Child Theme Using Plugin
Essential Requirements:
Make sure your parent theme is present in the Appearance -> Themes page, otherwise it will not work.
post-divider
Creating a Child Theme Manually
Step 1: Create a folder and name it . Ex: twentyten-child
Child themes are located in wp-content/themes in the WordPress installation. So, navigate there now and create a new folder for any child theme.
A best practice is to give your theme’s folder the same name as the parent theme and append it with -child. Because we are using the Twenty Fifteen theme, we will call our folder twentyfifteen-child.
Step 2: Create a file titled style.css
A style sheet contains the code that determines the design of a website. It should be named as style.css. It must include the below required header comment at the very top of the file. It is naming “style sheet header,” right at the beginning of the file. This tells WordPress basic info about the theme, including the fact that it is a child theme with a particular parent.
/*
Theme Name: Twenty ten Child
Theme URI: http://example.com/twenty-ten-child/
description: >-
Twenty ten Child Theme
Author: Your Name
Author URI: http://example.com
Template: twentyten
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, dark, two-columns, right-sidebar, responsive-layout, accessibility-ready
Text Domain: twenty-twenty-child
*/
The following data is required:
- Theme Name – It is a unique parameter of any theme.
- Template – the name of the parent theme directory. The parent theme in our example is the Twenty Twenty theme, so the Template will be twentyfifteen. You may be working with a different theme, so adjust accordingly.
Add remaining information as applicable. The only required child theme file is style.css, but functions.php is necessary to enqueue styles correctly (below).
Step 3: Enqueue stylesheet
It is another important step of stylesheet.
<?php
add_action( 'wp_enqueue_scripts', 'enqueue_parent_styles' );
function enqueue_parent_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' );
}
?>
Step 4 : Activate child theme
Now Zip the folder and upload it via Appearance -> Themes -> Add New. Once your folder and style sheet are present, go to “Appearance” → “Themes” in the WordPress back end and find your child theme there. When you click on “Theme Details” now, you will see the contents of the style sheet header. That’s what that info is for.