How to create a child theme in WordPress

FOR FELLOW DEVELOPERS

keiran keiran September 16th 2019

There are a wealth of great WordPress themes on the market, so why not use them! However, have you ever wanted to tweak your theme a little, add some custom functionality or change up the call to actions?

You’re in luck. This is where ‘Child themes’ come in to play…

What is a WordPress child theme?

 

A child theme is a theme that inherits the functionality and design of another (the parent theme).

When you have a child theme selected on your website, WordPress will check if your theme has any design or functionality code in it. As the code in a child theme overrides that of the parent theme. That being said if the child theme doesn’t have any additional design/functionality code then WordPress will refer to the parent theme’s files.

 

How to create a child theme in WordPress

 

Many high-end WordPress themes come loaded with a child theme. However, it’s a great idea to know how to create one manually just in case yours doesn’t. Don’t worry creating a child theme in WordPress is super easy.

The prerequisites needed is to have access to your sites cPanel (or FTP access) and a text editor of your choice. For the purpose of this tutorial I will be using the Twenty Nineteen theme & a FTP client.

Step 1: Creating the new theme directory

 

Firstly head over to your themes directory in cPanel or in my case FTP client. (/wp-content/themes)

Now create a new directory for the the child theme. You must name the directory twentynineteen-child. This must always be the name of the parent theme with a -child appended at the end.

Step 2: Create a style.css

 

You should now have an empty directory for your child theme. In this step we will create a stylesheet for it and add a few lines of code in it allowing us to set the name and parent theme.

Open the new directory (/wp-content/twentynineteen-child) and create a new stylesheet file in it. (style.css)

Now you’ll need to copy and paste these lines of code into style.css:

/*
Theme Name: Twenty Nineteen Child
Theme URI: https://www.yourwebsite.com/twentynineteen-child
Author: Keiran Martin
Author URI: http://www.keiranmartin.co.uk/
Description: My first child theme. Parent theme: Twenty Nineteen.
Template: twentynineteen
Text Domain: twentynineteen-child
*/
@import url(“../twentyseventeen/style.css”);

At this stage your child theme is actually ready to go and step 4 will show you how to get it live. However, if you’re going to make some functionality changes we’ve got one more step.

Step 3: Create functions.php file

 

You may wish to add some custom functionality to your WordPress theme. However, if you add custom code to your parent themes function.php file, the changes will be removed once you update your theme.

To prevent this you will need to create a new functions.php file within your child themes directory. (/wp-content/themes/twentynineteen-child)

Open the file with a PHP tag and you’re good to start adding your custom code.

<?php

//* Add your code

Step 4: Activate your child theme

 

Your child theme should now be created and ready to go, all that is left to do is activate the theme within your WordPress. Head over to Appearance>Themes in your WordPress admin panel and select your WordPress child theme.

Click the Activate button and you’re done!

That’s how to manually create a WordPress Child theme. Now your new theme is live, if you’re looking for some great WordPress plugins to use on your site here are my Top 5 WordPress Plugins for 2019

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *

<DIV>

GET IN TOUCH

</DIV>

Shoot me a message and I'll be sure to get back to you... or contact me on my social media!

My Social Media