WordPress is one of the most widely used web development frameworks and one of the biggest reasons behind this is the immense customization offered by it. Users can easily create their own sites and customize them without requiring the coding or programming proficiency.
WordPress Child Themes
A theme, the basic layout of the website is also completely customizable in WordPress. The WordPress developers have added the option for creating the child themes.
A Child Theme is a sort of sub-theme, which is generated from a WordPress Theme and is based on the default characteristics of its master or parent theme.
Why Do You Need A WordPress Child Theme?
Let's assume that you want to customize your website, but, also want your main theme to stay intact or unchanged, so that, if your changes don't go well, you can use the main theme. In such scenario, you can create and use a child theme.
A child theme enables you to modify the parent them as much as you want, without affecting the parent theme at all. Whenever you want to use the original parent theme, you can switch from the modified child theme to the parent theme.
Some of the astounding benefits of having a child theme include:
- Using the functionality offered by the sophisticated parent themes and frameworks, you can create your own customized design.
- The parent theme can be upgraded without losing the changes made to the child theme.
- A child theme offers an amazing way to learn programming, coding and how the themes work.
WordPress saves the child and the parent themes in different directories and every child directory contains its own functions.php and style.css files. If any more files are needed for the customization, they can be added.
By adding and modifying the relevant CSS and PHP files in the child theme, you can customize the website and modify everything on the website ranging from layout parameters to styling. The changes can be made to the coding and scripts being used by the child theme, even when they are not present in the parent theme.
What Happens When Visitors Visit Your Website?
When a visitor comes to your website, then WordPress first loads the child theme (being set as primary) and then the missing functions and styles are inherited from the parent theme. So, a high percentage of the background coding is pulled from the parent theme's directories, but are modified according to the child theme's parameters before the content of the page is displayed.
How To Create A Child Theme on WordPress?
1. The folder in which the downloaded WordPress is saved has a sub-folder /wp-content/themes. Create a new folder for your child theme in this folder. Give any name to the child folder.
2. Open the newly created folder and open a text editor in this folder, and paste the following code there. Save the file with the following code as the “style.css”
Theme Name: My Child Theme
Theme URI: techzzom.com
Description: My Child Theme Developed For Tutorial
Author URI: techzzom.com
This will create your child theme.
3. Now login to your WordPress and navigate to “Appearance” from the left menu. Now click “Themes”. Here you will be able to see your Child Theme. Click on the “Activate Button” to make the theme active on the site.
Since you have not changed anything in your theme, your site's appearance would not be changed at all. It will completely look like the original site.
Customizing The Child Theme
Each WordPress theme, whether the child theme or parent theme, has a style.css file located in the theme's main directory. Typically, it is the theme's primary stylesheet where all the CSS is placed. However, some themes only have the header information pertaining to the theme in this file. For such themes, the CSS file is generally located in a separate directory.
So, if you want to edit your theme, you would need a little bit of coding and CSS knowledge. CSS know-how would enable you to customize the different elements and layout of the theme.
With CSS knowledge, you can change the information in the headers and footers, and the other elements of the web page, like the placement of the blogs, web pages, the menu and much more.
Editing The Child Theme's Template Files
Every WordPress has a different layout, and the layout is generally divided into sections like header, footer, navigation menus, secondary widget area, content loop and the footer widget area.
Each of these layout sections is handled by the different files located in the theme's folder. These files contain the information about the appearance of the site. Most of the template files are named after the area which they represent. For instance, the header section's styling file is known as header.php, the footer's file is footer.php etc.
To edit these sections you can either make changes to the code or download the various plugins which enable to you to change the layouts or the content in these sections.