Customization of themes is the basic requirement of almost every client throughout the WordPress domain.The nature of the WordPress Template hierarchy and its structure are the major reasons why using a child theme is considered best practice and results in faster development time.
So here in the below article, let’s dig into the basics of a WordPress child Theme and how to create it.
WHAT IS CHILD THEME?
According to WordPress, a child theme is “a theme” that inherits the functionality of another theme, called the “parent theme”. In simple words,child theme is a theme which inherits and override the styles, functionality and templates of their parents.Basically child theme consists of:
– The child theme directory
HOW CHILD THEME WORK?
If you are using a child theme, WordPress will check for existence of a specific functionality in your child theme first. If it not present in your child theme then, it will use the parent theme. This is great because it allows you to modify only what you need.
PROS AND CONS:
Advantages of Using a Child Theme
– If we create a child theme we will not need to create a new theme from scratch. Which help to increase the speed of development and reduction in time to complete task.
– You will get benefit from updates to the parent theme without having to recode all your child themes.
– You can avoid irreversibly damaging your site by using a WordPress child theme.
– A child theme automatically inherits the parent theme’s features, styles, files and templates.
– There are a lot of free theme frameworks available which give you a wide range of functionality will not need too much customization in our child themes.
– A child theme built on a theme framework allows a great deal of flexibility without writing many lines code.
– If you forget to code for something, then there is always the parent theme’s functionality available as the fallback option.
Disadvantages of Using a Child Theme
– Disadvantage of using child themes is the time we need to invest to learn about the parent theme.
– You need to learn hooks and other functions that are used by parent themes or framework.
HOW TO CREATE IT?
Until now we have discussed what are the child themes and why to use them. Now we will discuss the steps to be followed to create one:
For creating a child theme,you will have to
1) Create a theme directory in your WordPress install
2) Create a stylesheet with information about your child theme
For this copy and paste the following code into the file you’ve just created:
Theme Name: Twenty Fourteen Child
Theme URI: http://yourwebsite.com/twentyfourteen-child/
Description: Demo child theme, based on Twenty Fourteen
Author: author name
Author URI: author url
Tags: //add your comma seperated list of tags here
3) Pull in the styles of your parent theme.
// This @import line loads the stylesheet from the parent theme
4) Overriding Parent Theme Template Files, styles and function.php file according to your requirement:
- Overriding your parent theme’s styles:
To modify your parent theme’s css, you can add any changes to your child theme’ s CSS file below the @import line. All new CSS information is added after the original theme’s CSS is loaded. Because our new css is added at the end after importing parent theme css, all new css styles will overwrite the original’s.
- Overriding your parent theme’s function.php file:
The functions.php of a child theme provides a smart, trouble-free method of modifying the functionality of a parent theme.A parent theme’s functions are always loaded along with the child theme, but if you need to add more custom functions to your theme then you can do so by creating a new functions.php file within your child theme folder. The new functions will be loaded right before the parent theme’s functions. So if you want to override a specific function from parent theme you can easily do that by redefining the functionality in child themes function.php.
- Overriding your Parent theme’s template files:
If you want to change more than just the stylesheet or functions, your child theme can also override the template files in the parent theme. Open the original template file and save a copy to the child theme folder with same file name and folder structure. Basically, the file structure has to match with the parent theme.
This is the list of the templates which can be override this way:
– Archive pages etc
This will be more easy you have a good knowledge of WordPress hooks and filters.
5) The final step is to activate the child theme from WordPress admin panel.
Hope that this article helps you to understand the basics of a WordPress child theme and has cleared your ideas about using and creating it.
Know the details of custom widget in WordPress at our blog- How to create custom widget in WordPress?
Additional Reference Resources:
Do you need to develop a best website for your business? Just relax, Solace is there to help you. Develop the best website with our exert’s team which will be the face of your business. They believe in effectiveness of using wordpress for web development. Contact us for web development that enhance your company’s profitability.