Articles on: Wordpress installation and configuration

How to create a child theme in WordPress

Here is how to create a child theme in WordPress for
Creating a child theme is recommended when you want to modify the code of an existing parent theme. This allows you to make customizations while still receiving updates to the parent theme. Here are the steps to create a child theme:
Create a new folder for the child theme inside the /wp-content/themes/ directory. A good naming convention is to use the parent theme's name followed by "-child". For example, if the parent theme is "Twenty Twenty-Two", you could name the child theme folder "twentytwentytwo-child".
Inside the child theme folder, create a new file called style.css. This is where you will add any custom CSS for your child theme.
In the style.css file, add the following header information at the top:
Copy code
Theme Name: Twenty Twenty-Two Child
Theme URI:
Description: Child theme for the Twenty Twenty-Two theme
Author URI:
Template: twentytwentytwo
Version: 1.0
Make sure to update the "Theme Name", "Theme URI", "Description", "Author", and "Author URI" with your own details. The "Template" line should match the directory name of the parent theme.
Create a new file called functions.php in the child theme folder. This is where you will add any custom PHP functions or hooks for your child theme.
To enqueue a custom stylesheet for your child theme, add the following code to the functions.php file:
Copy code
function twentytwentytwo_child_enqueue_styles() {
$parent_style = 'twentytwentytwo-style';
wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', array( $parent_style ), wp_get_theme()->get('Version') );
add_action( 'wp_enqueue_scripts', 'twentytwentytwo_child_enqueue_styles' );
This code ensures that the parent theme's stylesheet is loaded first, followed by the child theme's stylesheet.
You can now start customizing the child theme by adding CSS rules to the style.css file and PHP functions or hooks to the functions.php file.
By following these steps, you have successfully created a child theme for Remember to activate the child theme from the WordPress admin area (Appearance > Themes) after creating it. Any customizations you make to the child theme will override the corresponding styles or functions in the parent theme

Updated on: 08/05/2024

Was this article helpful?

Share your feedback


Thank you!