Are you tired of making changes to your WordPress site’s theme only to lose them during updates? Fear not, as a WordPress child theme can help you preserve your modifications. In this step-by-step guide, we’ll show you how to create a WordPress child theme.
Step 1: Create a new folder
Firstly, create a new folder for your child theme in the /wp-content/themes/ directory. Choose a unique and descriptive name for your theme.
Step 2: Create a style.css file
In your newly created child theme folder, create a new file named style.css. Add the following code to this file, replacing the placeholder text with your own information:
/*
Theme Name: My Child Theme
Template: twentytwenty
*/
Here, you should replace “My Child Theme” with the name of your child theme, and “twentytwenty” with the name of the parent theme you are using. This code tells WordPress that your theme is a child of the specified parent theme.
Step 3: Create a functions.php file
Next, create a new file named functions.php in your child theme folder. Add the following code to this file:
function my_theme_enqueue_styles() {
$parent_style = 'parent-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', 'my_theme_enqueue_styles' );
This code tells WordPress to enqueue both the parent and child theme stylesheets. It also ensures that the parent theme stylesheet is loaded before the child theme stylesheet.
Step 4: Activate your child theme
Once you’ve created your child theme folder and added the necessary files, you can activate your child theme in the WordPress admin panel under Appearance > Themes. You should now be able to modify your child theme without losing your changes during parent theme updates.
Conclusion
Creating a WordPress child theme is an easy and effective way to customize your WordPress site’s theme without losing your modifications during updates. By following the steps outlined in this guide, you’ll be able to create your own WordPress child theme in no time.