Creating a Child Theme the Proper Way
Child themes are an immensely useful tool that you can and should use for a variety of operations regarding your actual WordPress theme. The simplest explanation of what a child theme is would be that it is a sub-theme that has the same properties and functionalities as the parent theme. Consequently, its main purpose is for you to use it to modify your WordPress theme (your parent theme) without actually changing its files.
First of all, we would like to note that child theme is an extension of parent theme. Consequently, you can only create it as a duplicate of an existing WordPress theme. You can use a child theme for extending already created functions or adding new ones. Therefore, when the child theme is activated, every theme functionality stays the same and you should be able to keep on working as before.
We’ll assume your WordPress site is live and uploaded to a web server and that you’re already using your parent theme. In the following text we’ll guide you through how to create your own child theme.
Navigate to ../wp-content/themes and create yourthemename-child folder.
The best practice is to give your folder the same name as the parent theme. However, you’ll need to add the suffix -child.
Next, you’ll need 3 more core files, each of the different type.
Go to a text editor of your choice and create functions.php and style.css files.
In the style.css file you’ll give your child theme a heading with an appropriate description. Fields are pretty self-explanatory.
/* Theme Name: Twenty Nineteen Child Description: A child theme of twentynineteen Theme Author: WPKlik Author URI: https://wpklik.com/ Version: 1.0 Template: twentynineteen */ @import url("../twentynineteen/style.css");
And in functions.php file you’ll call your stylesheet using WordPress’ default wp_enqueue_scripts
function. This function registers your child theme’s style and performs an action to run it.
<?php // enqueue the child theme stylesheet Function wpklik_child_theme_enqueue_scripts() { wp_register_style( 'childstyle', get_stylesheet_directory_uri() . '/style.css' ); wp_enqueue_style( 'childstyle' ); } add_action( 'wp_enqueue_scripts', 'wpklik_child_theme_enqueue_scripts', 11);
Another thing you need is a thumbnail preview for your child theme. That’s the 3rd file mentioned above, in case you’re wondering.
Next, simply go to any photo editor and capture a screenshot of your theme. Name it screenshot.png (make sure you don’t create a JPEG image). Alternatively, copy the screenshot.png from parent theme and paste it in your child folder.
That would be all when it comes to creating your child theme. You should now be able to add custom functions and styles for your active theme. And you’ll do that without modifying the existing code. We hope this was helpful. Let us know in the comments below.
We hope this article to was helpful. If you liked it, please feel free to check out some of these articles as well!
erica
Will this work for a 2020 child theme as well
Jovan Kitanovic
Hi, thanks for writing in!
Yes, the method descriped in the article does not depend on the year so it will definitely work. 🙂