child theme

How to Create Child Theme in WordPress Without Plugin


Today we will see how to create child theme in WordPress without plugin. I have told earlier that with the help of plugin in WordPress, how you can make child theme of your WordPress theme, its link is given below.

How to Create Child Theme in WordPress With Plugin

Click me to learn how to create a child theme with the plugin

I hope we learned how to create child theme with plugin, now we will create child theme without plugin.

Step1:- Create a new folder in the “wp-content/themes/” directory of your WordPress installation. Name it something like “mytheme-child“. This will be the folder for your child theme.

Step2:- Create a new file in your child theme folder and name it “style.css“. Add the following code to the file:

/*
 Theme Name:   MyTheme Child
 Theme URI:    https://example.com/mytheme-child/
 Description:  MyTheme Child Theme
 Author:       Your Name
 Author URI:   https://example.com/
 Template:     mytheme
 Version:      1.0.0
*/

Make sure to replace “MyTheme” with the name of the parent theme that you want to create a child theme for, and update the other details as necessary.

Step3:- Create a new file in your child theme folder and name it “functions.php“. Add the following code to the file:

<?php
add_action( 'wp_enqueue_scripts', 'mytheme_enqueue_styles' );
function mytheme_enqueue_styles() {
    wp_enqueue_style( 'mytheme-parent-style', get_template_directory_uri() . '/style.css' );
    wp_enqueue_style( 'mytheme-child-style',
        get_stylesheet_directory_uri() . '/style.css',
        array( 'mytheme-parent-style' ),
        wp_get_theme()->get('Version')
    );
}
?>

This code will enqueue the parent theme’s stylesheet and your child theme’s stylesheet.

Step4:- Activate your child theme by going to “Appearance > Themes” in your WordPress dashboard and selecting your child theme. Your child theme should now be active and using the parent theme as a template.

Step5:- Customize your child theme by editing the files in your child theme folder. Any changes you make to these files will override the parent theme’s files.

Note:- It’s important to use the correct template name in the child theme’s style.css file. The “Template” value should match the name of the parent theme’s folder.


Related Posts

Leave a Reply

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