A “Child Theme” is like a patch we put on a “parent” theme, and it behaves almost as if it were simply a theme. For this reason, it is extremely important that you:
- Have the parent theme installed in your blog
- Create the snippet in your functions.php file with the information of your parent theme (see step 3)
- Upload your child theme (see step 4), in its own folder, separately from the parent theme (not inside)
WordPress has a Child Theme Handbook teaching you all about it. However, you may be not want to read the whole handbook now and with four simple steps you can create one now.
There are a couple of things to bare in mind though:
- To develop a Child Theme, all you need is a Text Editor, such as TextEdit on Mac. Not Word. It must be a text editor that allows to write in plain text and save the file as css, php, etc. However, using Sublime Text is game changing. And, if you develop it on a local host you’d work more efficiently.
- To install a Child Theme, however, you need a self-hosted website, or a WordPress.com plan (Business or Commerce)
Here’s how you create a child theme:
Step 1
Create a Folder in your machine, and name it twenty-twenty-child (for instance, if you’re using the Twenty Twenty Theme)
It is recommended to name the folder using the parent’s name plus the word “child”.
Step 2: A Style CSS file
Open your text editor, create a new file in plain text, and write with the following:
/*
Theme Name: Twenty Twenty Child
Description: A child theme for Twenty Twenty
Author: Your Name
Author URI: https://yourblog.com
Template: twentytwenty
Version: 1.0.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Tags: two-columns, right-sidebar
Text Domain: twenty-twenty-child
*/
Save the file, in the folder you’ve created, as style.css.
Step 3: a Function PHP file
Once again, open your Text Editor and create a new file in plain text. Then, write with the following:
<?php
//Child theme for twenty twenty
function my_theme_enqueue_styles() {
$parent_style = 'twentytwenty-style'; // Make sure here it's the parent theme.
wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-style',
get_stylesheet_directory_uri() . '/style.css',
array( $parent_style ),
wp_get_theme()->get('Version')
);
}
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
?>
In this snippet, the only thing you are to change is “twentytwenty-style” for your theme’s info. If you don’t do this right, the child theme won’t work.
Save your file, in the folder you’ve created, as functions.php.
These two files in your child theme’s folder, is all you need to create a child theme.
Step 4: Upload and Install Your Child Theme
To install your child you’ve got two options: upload it from the WordPress dashboard or through FTP.
Installing a Child Theme From the WP Dashboard
This is as simple as installing any theme:
- Zip you child theme’s folder
- At your blog, go to Apperance > Themes, and click on “Add New”
- The window will refresh giving you the chance to choose the zip file from your machine.
- Once you’ve uploaded it, click on “Install Now”
WordPress will check that the parent theme is installed. It will take a few seconds and then you’ll be able to activate it.
If you’ve customized your parent theme (site identity, colors, etc), these changes will be gone. You might need to select again your menus, widgets, etc.
Installing a Child Theme Trough FTP
Once you are logged in to your FTP, open wp-content > themes. You should see your theme’s folders there. Grab your child theme’s folder (not a zip file!), and drag it inside “themes”.
Then, head over to your WordPress dashboard, go to Apperance > Themes, and click on your Child Theme to activate it.