Today I will show you two different ways create a WordPress child theme.
WordPress is a popular content management system that powers millions of websites worldwide. One of the best things about WordPress is its flexibility, customization options and ease of use. When it comes to customizing a WordPress theme, it can be challenging to make changes directly to your theme, without losing the ability to update it. But that’s where a child themes come in. I will shown you two different ways to Create a WordPress Child Theme.
Creating a child theme manually is a straightforward process if you are familiar with coding. Here are the steps you need to follow, in order to make your own child theme.
Create a new folder in your WordPress themes directory (/wp-content/themes/
) and name it after your parent theme, but with a -child
in the end. F.e. if your theme is called twentytwentythree
, then your child theme could be called twentytwentythree-child
.
Create a new file named style.css
in your child theme folder and add the following code:
/*
Theme Name: twentytwentythree Child
Description: Twenty Fifteen Child Theme
Template: twentytwentythree
Text Domain: twentytwentythree-child
*/
Theme Name and Template are the only required fields in the style.css
file. The theme name can be anything you would like. Could be the name of the client or just Child theme. Template is the name of the folder your parent theme is located in.
Create a new file named functions.php
in your child theme folder and add the following code:
<?php
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles', 10 );
function my_theme_enqueue_styles() {
$parenthandle = 'parent-style'; // This is 'twentytwentythree-style' for the Twenty Twentythree theme.
$theme = wp_get_theme();
wp_enqueue_style( $parenthandle,
get_template_directory_uri() . '/style.css',
array(), // If the parent theme code has a dependency, copy it to here.
$theme->parent()->get( 'Version' )
);
wp_enqueue_style( 'child-style',
get_stylesheet_uri(),
array( $parenthandle ),
$theme->get( 'Version' ) // This only works if you have Version defined in the style header.
);
}
This code will enqueue the parent theme’s stylesheet and set up your own style.css
for editing.
Go to the Appearance menu in the WordPress dashboard and select Themes. Activate your child theme and you’re done!
If you’re not comfortable with manually creating a child theme, you can use a plugin to do it for you. Here are the steps you need to follow:
Now that you have created your child theme, you can use it to customize your WordPress theme without losing the ability to update it. Here are some examples of things you can do with a child theme:
You can make all the changes you want without affecting the parent theme. This means that you can update your parent theme without losing any of your customizations. Although it is a good idea to keep track of essential changes to the parent theme. If a security fix is applied to a file which you have overwritten, then you should make sure to update your file too.
I hope you found my two ways to create a WordPress child theme helpful. Child themes are a great way to customize your website without losing the ability to update your theme. Whether you prefer to create a child theme manually or with a plugin, the process is straightforward and easy to follow.
So, go ahead and create your child theme today and start customizing your WordPress website!