How to create a child theme in WordPress
Creating a child theme in WordPress is a great way to customise and extend the functionality of an existing theme without losing the ability to upgrade the parent theme. By creating a child theme, you can make changes to your website without modifying the source code of the parent theme, which will make it easier to update the parent theme without losing your customisations.
Here are the steps to create a child theme in WordPress:
- Start by creating a new folder in the
wp-content/themes
directory of your WordPress installation. This folder will contain your child theme files. - Next, create a new file called
style.css
in the child theme folder. This file will contain the styles for your child theme. - Open the
style.css
file in a text editor and add the following code at the top:
/*
Theme Name: My Child Theme
Description: A description of my child theme
Author: Site Schema
Author URI: https://www.siteschema.com/
Template: parent-theme
*/
- Replace Theme Name, Description, Author, and Author URI with your new child theme information, and “parent-theme” with the name of the parent theme. Example: To create a child theme from WordPress‘ Twenty Twenty-Two theme the template would be twentytwentytwo
- Add any custom styles for your child theme to the
style.css
file. These styles will override any matching styles in the parent theme. - To enable your child theme, go to the
functions.php
admin dashboard and navigate to Appearance > Themes. Your child theme should appear in the list of available themes. Click on the Activate button to use the child theme on your website. - If you want to customise the functionality of your child theme, you can create a new file called
functions.php
in the child theme folder. This file will be loaded automatically when your child theme is active, and you can add custom code to it to extend the functionality of the parent theme. - To ensure that your custom styles are loaded, open the
functions.php
file in a text editor and add the following code:
<?php
add_action( ‘wp_enqueue_scripts’, ‘my_theme_enqueue_styles’ );
function my_theme_enqueue_styles() {
wp_enqueue_style( ‘child-style’,
get_stylesheet_uri(),
array( ‘parenthandle’ ),
wp_get_theme()->get( ‘Version’ ) // Only if you have Version defined
);
}
In conclusion, creating a child theme in WordPress is a simple and effective way to customise and extend an existing theme without losing the ability to upgrade the parent theme. By following the steps outlined above, you can create your own child theme and start making customisations to your WordPress website.
Need help with Child Themes?
We’re here for you
We love solving complex problems and want to help you solve yours. We’ll take care of the heavy lifting so that you can focus on your audience.