How to make a custom child theme In WordPress?

0 0
Read Time:2 Minute, 21 Second

In today’s world, WordPress is one of the most useful platforms for e-commerce websites/platforms. In WordPress, we can easily manage and convert the existing code using PHP. Many time maximum of people doesn’t know how to override an existing code so that nothing will effect if we update our plugins or theme.

Child themes help us to make custom CSS functions filters and hooks to make custom features. In the child theme, function.php play an important role to reuse importing the main theme CSS.

Using this we can moreover make our own function to make a high-level website.

For making such edits and making a custom child theme of any theme we can use PHP code to make connections and get enabled the child theme in the admin of WordPress.

You can follow the below mention script to make the child theme.

The first step make one folder under the themes folder in WordPress

Path: /wp-content/themes/child-theme

Once you make the folder with the name of the child on it you need to open that folder and again make a file function.php

add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
function my_theme_enqueue_styles() {
    wp_enqueue_style( 'child-style', get_stylesheet_uri(),
        array( 'parenthandle' ), 
        wp_get_theme()->get('Version') // this only works if you have Version in the style header
    );
}

Once we are done with adding the code we need to make a style.css file so that we can hook up the existing CSS with child one.

After making the child theme you need open the style.css file of the main theme and copy the theme info and paste it into your style.css file.

The code will look like this:

Under that file copy and paste this:

/*
 Theme Name:   Twenty Fifteen Child
 Theme URI:    http://example.com/twenty-fifteen-child/
 Description:  Twenty Fifteen Child Theme
 Author:       John Doe
 Author URI:   http://example.com
 Template:     twentyfifteen
 Version:      1.0.0
 License:      GNU General Public License v2 or later
 License URI:  http://www.gnu.org/licenses/gpl-2.0.html
 Tags:         light, dark, two-columns, right-sidebar, responsive-layout, accessibility-ready
 Text Domain:  twentyfifteenchild
*///do you custom css here…

You can even modify these details according to your need.

If you want to make a custom js file then you can easily make and call to up in the function file.

In WordPress under our child theme, we can also make pages and post custom templates which will be done under the templates folder in the child theme.

Path:wp-content/themes/child-theme/templates/{temaplate-name}.php

Hope that information helps you to make a custom child theme of any existing theme in WordPress.

For more details, you can check the below-mentioned youtube video.


Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleepy
Sleepy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %