Skip to main content
PHP Blog

Back to all posts

How to Create A Child Theme In WordPress?

Published on
15 min read

Table of Contents

Show more
How to Create A Child Theme In WordPress? image

Creating a child theme in WordPress allows you to make changes to your website's design and functionality without modifying the parent theme files. Here is a brief explanation of how you can create a child theme:

  1. Firstly, access your WordPress installation via FTP or cPanel file manager. Navigate to the "wp-content/themes/" directory.
  2. Create a new folder within "themes" and give it a name (e.g., "child-theme").
  3. Inside the new child theme directory, create a new file called "style.css". This file will hold the CSS code for your child theme.
  4. Open the "style.css" file with a text editor and add the following code at the top:

/* Theme Name: Child Theme Template: parent-theme-folder-name */

/* Add your custom CSS code below */

Replace "Child Theme" with the desired name of your child theme and "parent-theme-folder-name" with the name of the parent theme's directory.

  1. Save the "style.css" file after adding your custom CSS code for the child theme.
  2. If you want to modify any template files of the parent theme, create a new file with the same name and path as the file in the parent theme. Then, you can modify the contents of this file to make changes specific to your child theme.
  3. Zip the entire child theme folder.
  4. Go to your WordPress admin dashboard and navigate to "Appearance" -> "Themes".
  5. Click on the "Add New" button at the top and then select the "Upload Theme" option. Upload the zipped child theme folder and click "Install Now".
  6. After installation, activate the child theme.

Now you have successfully created and activated your child theme in WordPress. You can start making modifications specifically to the child theme, ensuring that your changes won't be lost when the parent theme updates.

How to override parent theme styles using a child theme in WordPress?

To override parent theme styles using a child theme in WordPress, follow these steps:

  1. Create a new folder in your WordPress themes directory and name it as per your preference (e.g., childtheme).
  2. Inside the childtheme folder, create a new file named style.css.
  3. In the style.css file, add the following code to create the child theme:

/* Theme Name: Child Theme Theme URI: //Your theme URI Description: Child theme for Parent Theme Author: Your Name Author URI: //Your author URI Template: parenttheme Version: 1.0 */

/* Add your styles below */

Note: Replace parenttheme with the name of the parent theme you want to override.

  1. Save the style.css file.
  2. Create any additional files in your child theme directory that you want to override from the parent theme. For example, if you want to override the header.php file from the parent theme, create a new header.php file in your child theme directory.
  3. In the child theme's functions.php file (create one if it doesn't exist), include the parent theme's stylesheet. Add the following code:
  1. Save the functions.php file.
  2. Activate the child theme from the WordPress dashboard by going to Appearance > Themes.
  3. Now, you can start adding your custom CSS styles in the style.css file of the child theme. These styles will override any corresponding styles from the parent theme.

By following these steps, you have successfully created a child theme and can now make customizations that take precedence over the parent theme styles.

How to set up a child theme using the WordPress theme customizer?

To set up a child theme using the WordPress theme customizer, follow these steps:

  1. Create a new folder for your child theme in the "wp-content/themes" directory of your WordPress installation. Name the folder something meaningful, such as "mytheme-child."
  2. Create a new file in your child theme folder and name it "style.css." Open this file in a text editor.
  3. In your child theme's style.css file, start with a comment block to provide some information about your child theme. For example:

/* Theme Name: MyTheme Child Template: mytheme */

Replace "MyTheme Child" with the desired name for your child theme and "mytheme" with the directory name of the parent theme you are using.

  1. Save the style.css file.
  2. Create another file in your child theme folder called "functions.php" and open it in a text editor.
  3. In the functions.php file, add the following code to enqueue the parent theme's style sheet: