Creating a child theme in WordPress is an essential step for making safe and update-friendly customizations to your website. A child theme allows you to modify your site's appearance and functionality without altering the parent theme, ensuring that updates to the parent theme won't overwrite your changes.
What Is a Child Theme?
A child theme is a separate theme that inherits the features and styles of its parent theme. It acts as a sandbox where you can add or modify code safely. This approach is recommended for developers and site owners who want to customize their website without risking the loss of changes during updates.
Steps to Create a Child Theme
1. Create a New Folder
Using an FTP client or your hosting file manager, navigate to wp-content/themes. Create a new folder and name it after your parent theme with "-child" appended. For example, if your parent theme is "twentytwenty," name the folder "twentytwenty-child."
2. Add style.css File
Inside your child theme folder, create a file named style.css. Add the following header comment at the top, customizing it with your theme details:
/* Theme Name: Twenty Twenty Child Template: twentytwenty */
3. Enqueue the Parent Theme Styles
In your child theme folder, create a functions.php file. Add the following code to load the parent theme's stylesheet:
<?php function enqueue_parent_styles() { wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' ); } add_action( 'wp_enqueue_scripts', 'enqueue_parent_styles' );
Activating Your Child Theme
Go to your WordPress admin dashboard, navigate to Appearance > Themes. You should see your new child theme listed. Click Activate to enable it. Your website will now use the child theme, ready for customizations.
Making Customizations
With your child theme active, you can safely add custom CSS to style.css or override template files by copying them from the parent theme into your child theme folder and editing them as needed. Remember to keep your modifications organized and well-documented.
Conclusion
Creating a child theme is a best practice for customizing WordPress sites securely. It protects your modifications from being overwritten during theme updates and makes managing custom code easier. Follow these steps to set up your child theme and start customizing confidently.