How to Create a WordPress Child Theme?

wordpress child theme

WordPress themes are one of the best things about the website development. It is great for the web development with many inbuilt designs and features. In the last blog post we already have discussed about the advantages of WordPress Child theme and why we should use. Here we will try to get a basic idea about how to develop a child theme.

Requirements

For creating a custom child theme, it is required to have basic knowledge of HTML/CSS and WordPress. Get an idea about the WordPress folder structure too, as it will help to create the child theme.

Create your WordPress Child Theme

  • After downloading and installing the WordPress in your system, open the folder /wp-content/themes.
  • After that create a new folder there and name it your new child theme. For example- DS Child.
  • Now create a stylesheet file and name it as style.css. In the stylesheet, you must keep all the information about your theme. You can get reference with the stylesheet of another template or parent theme.

Your stylesheet should have following info-

/* Theme Name: DS Child
Theme URI: http://yourwebsite.com/ds-child/
Description: My first child theme, based on DS
Author: Team DS
Author URI: URL of official website of the parent theme
Template: DS
Version: 1.0.0
Text Domain: ds-child */

Theme name and Template are 2 mandatory field from the above details.

Once you have created a child theme folder and stylesheet. It will show in the themes section. Now go in the WordPress admin panel-> Appearance-> Themes-> Select the child theme you created and activate it.

Next step is to create functions.php file. This file allows to add functionalities and features in the WordPress theme. Create a text file, named it functions.php and put the code – “

Inherit styles and features from the parent theme

After the basic theme creation, you must want designs and features as your parent theme. Now you need to inherit the stylesheet of your parent theme. The best way to do that is to load the parent’s stylesheet by using function wp_enqueue_style().

Add the following code in your functions.php file.

add_action( 'wp_enqueue_scripts', 'enqueue_parent_styles' );
function enqueue_parent_styles() { wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' ); }

Now reload your theme again and see the difference. You successfully created the WordPress child theme.

Customizing Child Theme

Once you have created the child theme and it looks same as the parent theme. You can create custom CSS and functionalities for the theme. By using your child theme’s stylesheet, you can change the entire layout of the theme.

Not only the CSS but you can override any feature of your parent theme. Basically, WordPress checks the code first in the Child theme and then in the parent theme. For example, if you will create a header.php file in your child theme, WordPress will execute that code instead of the parent theme’s header.php.

You can easily create a child theme by using some simple copy paste. Creating a child theme will save you from several issues in the future. For more about Web development, visit our web development services page. Contact us for any other details.