What is a child theme in WordPress
Posted on November 13, 2023by SplashCodes Team
WordPress Child Theme
A child theme serves as an extension of the parent theme, inheriting its attributes and functionalities.
Why do we need a child theme
The purpose of a child theme is to allow users to customise the options and add additional changes without editing the core files of the parent theme. Having a child theme is important to not lose the changes when updating the parent theme. It is considered as the safest way to make any changes to the theme that is in active state.
How to create a child theme manually with simple steps
Below are the step-by-step instructions to create a child theme manually in WordPress through dashboard
1. Log in to WordPress Dashboard, Go to plugins -> Add New search for File Manager
2.You will find below suggestions. Click on Install Now and activate any plugin
3. Go to WP File Manager and navigate to /wp-content->themes and find the theme you wanted to add a child theme (In my case it is Twenty Seventeen)
4. Create a folder with the same name as the parent theme and add the word child (In my case it is Twenty Seventeen Child)
5. Create the 2 files inside the folder with the extensions style.css and function.php .
6. Add below code to style.css and Save it.
/* Theme Name: Name-child Theme Theme URI: http://yourdomain.com Description: Name-child Child Theme Author: Your Name Author URI: http://yourdomain.com Template: Name-child Version: 1.0.0 Text Domain: twenty seventeen-child Licence: GNU General Public License or later Licence URI: http://www.gnu.org/licenses/gpl-2.0.html Tags: light, dark, two-columns, right-sidebar, responsive-layout, accessibility-ready */
Note :
Adjust all the values accordingly. The crucial field is ‘Theme Name,’ as it informs WordPress about the parent theme your child theme is built upon. After making the changes, click Save and Close.
7. Add below code to function.php and save it. This script will enqueue the parent theme stylesheet.
<?php add_action( 'wp_enqueue_scripts', 'enqueue_parent_styles' ); function enqueue_parent_styles() { wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' ); } ?>
8. Congratulations, you are all done with the child theme creation.
Go to Appearance ->Themes and you can find your child theme is ready to activate.