In this tutorial, you will learn how to make a child theme for your WordPress websites regardless of what theme you are using. To do this, you essentially have to create a folder with two files in it, and that’s it!
Please note that you will need access to your website server files, whether that’s via FTP or SSH.
WordPress Child Theme Tutorial
The fundamental parts of a child theme in WordPress is a directory with the following two files inside of it.
- style.css
- functions.php
Let’s first start by making a directory for your child theme. In my case, I want to make a child theme for the Twenty Twenty theme. Inside of the wp-content/themes directory, there is a folder for the Twenty Twenty theme called twentytwenty, so I will make another folder at this same level called twentytwenty-child. If you are logged in to your sever via SSH, the following commands will do this for you.
cd /var/www/html/wp-content/ mkdir twentytwenty-child cd twentytwenty-child/
Next, make the style.css file with the following content.
/* Theme Name: Twenty Twenty Child Text Domain: twentytwenty-child Version: 1.0 Template: twentytwenty Author: Tony Teaches Tech Author URI: https://tonyteaches.tech License: GNU General Public License v2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html */
Make another file called functions.php.
<?php // incherit parent theme styles add_action( 'wp_enqueue_scripts', 'enqueue_parent_styles' ); function enqueue_parent_styles() { wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' ); }
The above code inherits the parent theme styles.
For good measure, change ownership of the directory and files to the www-data user and group.
cd .. chown -R www-data:www-data twentytwenty-child/
Back in WordPress under the Appearance > Themes section, you can now activate your new child theme.