Creating WordPress Child Theme Method Two

If you want to overwrite the parent theme functionality and add some of the exciting features to your site, then, creating WordPress child theme will help you a lot. Well, for your knowledge, there are lots of methods on creating the WordPress child theme. But, it is not sure that which is the best method and which one is worst. We have already discussed about one of the method on creating WordPress child theme through this link below:

Creating WordPress Child Theme Method One

The main drawback of the above mentioned method is that, we have used the import method in adding the parent theme styling code, which will take the site load time in every step of the browsing, hence, can increase the site load time as well as it will take more bandwidth while serving the site to the user since it will always load the CSS code of the parent theme, taking some bandwidth of the server due to the import method. Here we will be describing about the other method for creating WordPress child theme.




Creating the style.css is in same way, the only difference in  this file is, we should not add the import code in it at all. The style code will be like this one:

So, if we are not using the import code for importing the CSS code of the parent theme, then, there should be other method, right? Well there is, the method for it is by using the enqueue method, which is the WordPress default function to add the Custom CSS and JS files to your site. By enqueueing the style of the parent theme, then, it will be loading only once and bandwidth of the server will also be decreased by some means.

So, in order to enqueue the parent theme’s CSS code to your child theme, we have to use the function and hook it to the  wp_enqueue_scripts function, which is the WordPress default function to add the custom CSS and JS files. The code which need to be added in functions.php file of the child theme for this is given below:

Here, in the above code, theme_enqueue_styles is the created function to add or enqueue the style of the parent theme, through the child theme, which is hooked to the function wp_enqueue_scripts, which is for enqueueing the custom CSS and JS codes in WordPress. Now, after applying the above code, parent theme as well as the child theme’s CSS code will be enqueued one after the other, making the parent theme CSS code to be overwritten by the help of the child theme. And all of the remaining parts are as described in the other post, whose link is provided above.

Now, if you have followed the above tutorial properly, then, we can assume that you are more familiar in creating WordPress child theme than before and can make your site look even more beautiful on your users eye with the help of the child theme.

, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Post navigation

Bishal Napit

Bishal Napit is a WordPress theme developer from Tansen, Palpa, with a passion to learn more on WordPress.

Leave a Reply