If you modify a theme directly and it is updated, then your modifications may be lost. By using a child theme you will ensure that your modifications are preserved. – WordPress Codex
I recommend creating a Child Theme before you make any customisations to the Parent Theme’s options. Otherwise you may need to use a tool like the Child Theme Configurator plugin to copy over the Parent Theme’s settings to the Child Theme.
A Child Theme template
Download a simple template for creating a WordPress Child Themes.
The Child Theme directory
Make a directory for the child theme in the themes
directory, on the same level as the parent theme. It is recommended (though not required) that the name of your child theme directory is appended with -child
eg. sitename-child
The style.css file
Create a style.css
for the child theme similar to the following.
/*
Theme Name: Site Name
Description: Child theme for Parent Theme Name
Author: Ben Pearson
Author URI: http://benpearson.com.au
Template: parentthemedirectory
Version: 1.0.0
*/
// Add your child theme CSS here
All the fields in the header are optional except Theme Name
and Template
.
Theme Name
is the name of your child theme – usually the site name.Template
is the directory name of the parent theme and is case sensitive.
The functions.php file
Note that the previous method was to import the parent theme stylesheet using @import: this is no longer best practice. The correct method of enqueuing the parent theme stylesheet is to add a wp_enqueue_scripts action and use wp_enqueue_style() in your child theme’s functions.php. – WordPress Codex
Create a functions.php for the child theme similar to the following.
<?php
/**
* Functions
*/
add_action( 'wp_enqueue_scripts', 'sitenameprefix_theme_enqueue_styles' );
function sitenameprefix_theme_enqueue_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}
Note this example.. “will only work if your Parent Theme uses only one main style.css to hold all of the css. If your theme has more than one .css file then you will have to make sure to maintain all of the Parent Theme dependencies.” –WordPress Codex
References
- Child Themes in the WordPress Codex
Thanks a lot for sharing this.I am currently working in a web development company as wordpress developer.This is an added information for me to create a child theme.Good Work.