Setting up a WordPress Child Theme

Many of us want to customize something in theme. Are you also looking to add or edit something in the theme that you are using? If yes, then you have come to the right place.

Child themes allow you to make changes without affecting the original theme’s code, which makes it easy to update your parent theme without erasing your changes.

Creating a Child Theme

Firsty, create a new folder in your themes directory. You can do so using the cPanel or via FTP. The themes directory is the wp-content/themes. So, lets name the folder as test-theme-child. You can name it whatever you like but remember there should not be any space in the folder name. It is a common approach to name child theme as the parent theme plus -child added on the end.

Secondly, inside the test-theme-child folder create a file called style.css and fill in the information as shown below. This is the only file required to make a basic child theme.

/*
Theme Name: Test theme child
Theme URI: http://example.com/test-theme-child/
Description: Description about this Child Theme
Author: your name
Author URI: http://yoursite.com
Template: parent-theme-slug
Version: optional
Tags: optional
Text Domain: test-theme-child
*/
 
/* =Theme customization starts here
-------------------------------------------------------------- */

Lastly, now to activate the child theme, in the dashboard go to Appearance->Themes. Look for the child theme you created and activate it. That’s it. Also, make sure the parent theme is also present in the installed themes for the child theme to work. If you now visit your site it should look all same just like when the parent theme was activated.

Making Further Changes

Editing the functions.php file
Functions.php file is where theme’s main functions are usually kept. If you need to add custom functions then you need to create functions.php file within the child theme folder and add your functions code inside it. These functions will be loaded before and in addition with the parent theme functions.

/**
* Child theme functions file
*
* The right way to make a child theme is to
* enqueue the stylesheet of the parent in the
* functions file of the child
*
*/
function parent_theme_css() {
wp_enqueue_style( 'parent-theme', get_template_directory_uri() . '/style.css' );
}
add_action( 'wp_enqueue_scripts', 'parent_theme_css' );

Wrapping Up

Hopefully now you are able to create a child theme and make the customization that you like. Want to say something? Add it in the comments and I will get back to you. Enjoy!

Leave a Reply

Your email address will not be published. Required fields are marked *