Themes

How to Create a WordPress Child Theme

How to Create a WordPress Child Theme

A child theme is a theme that allows you to make changes to an existing theme (the parent theme). It’s the best way to add or change functionality in an existing theme without touching the original theme’s source files. This helps you to keep your customizations when you update the parent theme, and your changes won’t be lost.

Step 1: Create a New Folder

First, log into your WordPress installation files through FTP, this can be done either through a client like FileZilla or your hosting provider’s File Manager. If you don’t have access to your hosting cPanel, you can install the WP File Manager plugin from your WordPress dashboard to access the root directory of your WordPress site.

Follow these simple steps to install the WP File Manager plugin:

After the installing the WP File Manger Plugin go ahead and do the other steps as mentioned in the blog post.

Go inside the directory /wp-content/themes/. It stores all the themes for your WordPress site.

goto wp content

Click on the Themes folder inside the wp-content directory.

Note

Do not use spaces or special characters in the folder name, just lowercase letters and dashes for clarity

child theme folder

Step 2: Create a style. css File for the Child Theme

Inside your newly created child theme folder create a new file called style. css. This file will hold the important information to identify the child theme and make WordPress recognize it

style css file

Open the style.css file and paste the following code into it. I am creating the child theme for Astra that’s why I just wrote the Template name to Astra. You can write your parent theme name.

/*
Theme Name:   Astra Child
Template:     astra
Author:       Your Name
Description:  A child theme for the Astra parent theme.
Version:      1.0
*/

Explanation of the Code:

Theme Name: This is how the child’s theme name will be shown in your WordPress dashboard.

Template: folder name of parent-theme (case-sensitive) If your parent theme folder is Astra, you must write Astra here.

Author: This is optional and can be your name or your company’s name.

Description: A brief description of the child theme is optional but useful for reference.

Version: the version number of the child theme It is derived from the version number given to the software (ie. You start at 1.0 and increment each time you make an update.

Save the style.css file.

Step 3: Create a function. php File for the Child Theme

Then, create another file in the child theme folder and name it functions. php. These files are used to load the stylesheet and add any custom PHP functionality if necessary.

Open the function.php file and paste the following code into it.


// Enqueue parent theme styles
function astra_child_enqueue_styles() {
    // Load parent theme stylesheet
    wp_enqueue_style('parent-style', get_template_directory_uri() . '/style.css');

    // Load child theme stylesheet
    wp_enqueue_style('child-style', get_stylesheet_uri(), array('parent-style'));
}
add_action('wp_enqueue_scripts', 'astra_child_enqueue_styles');

Step 4: Activate the Child Theme in WordPress

Once you’ve created both the style.css and functions.php files, log in to your WordPress admin dashboard. Navigate to Appearance > Themes. You should see the child theme listed among the available themes. Click Activate to enable the child theme.

Step 5: Edit the Child Theme

Now that the child theme is activated, you can go through and make changes to the child theme without altering the parent. Add custom CSS rules directly to the child theme’s style. Editing the functions also helps to extend functionality or CSS file. php file.

If you want to override a specific template file from the parent theme (e.g. header. php, footer. php, or single. php), you just copy that file from the parent theme to your child theme’s folder. WordPress will always use the child theme’s version of the file.

If you want to customize the layout for single blog posts, for example, copy single. php file went from the parent theme to the child theme folder. Then pass an edit to tailor it to your needs.

Child Theme Advantages

Creating a child theme helps to ensure that your modifications stay intact when updating the parent theme. This allows you to customize your website according to your needs safely and flexibly.

Conclusions

Creating a child theme in WordPress is a good way to extend your website without changing the original parent theme files. This not only allows you to add design and functionality without the worry of updates overwriting your code but also enables peace of mind knowing that your changes are safe and cannot be overwritten in future updates. Once you have a parent and child theme you can safely start making your WordPress blog look as you wish. This method is great for developers and website owners who want long-term maintainability.

FAQS Child Theme

What will happen if I update the parent theme after creating a child theme?

Updating the parent theme replaces all the files of the parent theme with the latest version. All the settings will be reverted to their original state but since your customizations are in the child theme, they are unaffected. That’s one of the key benefits of using a child theme.

Using a child theme without being a developer?

Yes! Creating and using a child theme is very easy even if you are not a developer. You are familiar with editing files through a code editor or a hosting control panel. Once it is fully set up you can easily customize your site by adding custom CSS or overwriting templates.

What happens if your parent theme is deleted by mistake?

A child theme needs a parent theme to function, and if the parent theme is deleted, so is its child! To fix this, you’ll want to reinstall the parent theme and ensure that it’s activated as the base theme.

Can plugins be added to my child's theme?

Plugins are separate and not dependent on the theme or child theme in WordPress (they are maintained separately). However, you may add your PHP functionality to the functions of your child theme. php file that can occasionally even copy what a plugin does. For more advanced functionality, a plugin is often much more efficient.