A WordPress child theme is a theme that inherits the functionality of another theme, called the parent theme. Child themes are typically used to make modifications to a pre-existing theme without altering the parent theme’s code. This is useful when you want to make customisations to a theme without losing the ability to update the parent theme. If you add your changes directly to the parent theme those changes could be lost when you update the theme. So let’s get straight into it and take a look at how to create a new WordPress child theme.

Step 1 – Create a new folder for the child theme

The first step in creating a child theme is to create a new folder for the child theme in your WordPress theme directory. This folder should be located in the “wp-content/themes” directory, with a descriptive name like “my-child-theme.”

Step 2 – Create a style.css file

After that he next step is to create a new file called “style.css” in your child theme’s folder. This file is used to define the child theme’s styles and also to inform WordPress that it is a child theme. At a minimum, the style.css file should contain the following code:

<span class="hljs-comment">/*
Theme Name: My Child Theme
Theme URI:
Description: A child theme of Twenty Twenty
Author:
Author URI:
Template: twentytwenty
Version: 1.0
*/</span>

The theme name, theme URI, description, author, and author URI should be filled out with appropriate information. The template field should contain the name of the parent theme that the child theme is using, which in this case is “twentytwenty”.

Step 3 – Create a functions.php file

The next step is to create a new file called “functions.php” in the child theme’s folder. The functions.php file is used to add custom functionality to your child theme. At a minimum, it should include the following code:

<span class="hljs-meta"><?php</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">my_child_theme_enqueue_styles</span>() </span>{
<span class="hljs-title function_ invoke__">wp_enqueue_style</span>( <span class="hljs-string">'parent-style'</span>, <span class="hljs-title function_ invoke__">get_template_directory_uri</span>() . <span class="hljs-string">'/style.css'</span> );
}
<span class="hljs-title function_ invoke__">add_action</span>( <span class="hljs-string">'wp_enqueue_scripts'</span>, <span class="hljs-string">'my_child_theme_enqueue_styles'</span> );

This code tells WordPress to use the parent theme’s style.css file by enqueuing it as a dependency for the child theme. This ensures that any styles defined in the parent theme will be used in the child theme.

Step 4 – Create a screenshot

A screenshot is an image which represents your child theme. A screenshot measuring 880×660 pixels and called “screenshot.png” is recommended. WordPress will display this image in the theme repository when you upload your child theme.

Step 5 – Activating the child theme

Once you have completed steps 1-4, you can activate your child theme from the WordPress admin panel by going to Appearance > Themes. Your new child theme will now appear in the list of themes. You can activate it just like any other theme.

Step 6 – Modifying the child theme

After you activate your child theme you can start modifying it. You can make changes to the styles in the style.css file, add new functions to the functions.php file, or create new templates. Any modifications made to the child theme will not affect the parent theme, which allows you to update the parent theme without losing your customisations.

It is important to note that while you can make any type of modification on a child theme, it is important to limit yourself to only the necessary changes that are needed. This will help you to maintain your child theme and keep it updated with the parent theme. If the parent theme is updated, you don’t have to worry about losing your customisations.

Creating a WordPress child theme is a useful technique for customising an existing theme without altering its code. Creating a child theme lets you make modifications to a theme and retain the ability to update the parent theme. It’s a straightforward process – with a little knowledge of HTML, CSS and PHP anyone can easily create a child theme. Remember that creating a child theme allows you to only make the changes you need. You can maintain your child theme, keep it updated and ensure your customisations don’t get lost.

Let's Get In Touch!


Ready to start your project? Get in touch to have a chat!