A WordPress child theme is that theme which adopts the functionality of the parent theme(another theme). A WordPress child theme is the safest way to make changes in existing theme. It allows you to change the design and functionality of theme without making any edit to the parent theme. Creating a child theme becomes important when you have to modify/add any template file, add/edit CSS styles and images. As the child theme is saved separately, you have no risk of losing any customization upon updating your theme. But, always keep in mind that if you edit original/core theme, all your customization will be vanished when you update your theme.
Key benefits you enjoy while using a child theme for WordPress:
· Easy Extension:
When you create a child theme by making use of a powerful theme framework, it offers you immense flexibility without writing numerous codes. You can add new functionality, modify the template files and functions and a lot more.
· Safe fallback:
When you create a theme, you are supposed to think of all possible situations and consequently code for them. When you are creating a child theme and you forget the code of something all of a sudden, you can easily make use of the parent theme’s functionality toper form your work smoothly.
· Safe Updates:
As a child theme inherits the features, styles and templates of the parent’s theme automatically, you become enable to make necessary changes to your website without using the parent theme. This allows you to update it safely for all modifications you do in the child theme.
How Child Theme Works:
When you create child theme and activate it, first of all,WordPress will search the template files in the child theme and then after in the parent theme. If the file is not found in the child theme, it will go back to the parent theme folder.
How to create a Child theme:
The entire process to create a WordPress Child theme is detailed here below
1. Select a parent theme:
In order to create a child theme, you need to select a parent theme you want to add features or modify. As your newly created theme will inherit everything from the parent one, you need to select parent themes carefully and wisely. Go for a solid theme with good layout options and good SEO so that you can get a solid base for your work.As soon as you have acquired the basics ofthe child theme creation, you can easily start creating theme overpopular frameworks such as
Or Go for Some open source frameworks like:
2. Install the parent theme:
Now you need to download and install the theme which is base for your work. Follow the below mentioned steps:
- Go to the Admin section of your WordPress installation(http://your-site-url/wp-admin/),
- Choose Appearance -> Themes from the left side of your screen and
- Select Add New and search for the parent theme. If it not reinstalled, then download and install it.
3.Create a child theme:
Create a child theme folder where all its files will be stored. You can do this in various ways, but,FTP and ssh the most common methods. Create it and give it a name. There must be two files inside that folder- style.css andfunctions.php
As soon as you have those files, add this to style.css.
/*
Theme Name: Twenty Fifteen Child
Theme URI: http://the-url-where-theme/can-be-downloaded
Description: Twenty Fifteen Child Theme
Author: Your name
Author URI: http://your-website
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: responsive, blog
Text Domain: twenty-fifteen-child
*/
You can easily modify those lines in accordance with your requirement and you cant write at your discretion at only one time as it must appear in the folder of the parent theme. You also need to createa functions.php that will keep vacant for some moments.Now, you can activate the theme from Appearance -> Themes * menu in the Admin page of your WordPress Admin Panel.
As soon as you active it, you will see a blog with no theme at all. Now, you can customize it for your new theme.
4. Customization of your newly created theme:
You need to understand that any file you have in your child theme’s folder will replace the original one in parent folder, with the exception of functions.php where contents will be added to the parent’s functions.php file, but, at it’s top, child functions are loaded before parent’s ones.
5. Import parents styling:
You need toimport the parent’s styling first of all so that you can modify them in place of creating all things once again. To do so,
In order to do it, copy this snippet in your child’s functions file.
<?php
add_action( ‘wp_enqueue_scripts’, ‘theme_enqueue_styles’ );
function theme_enqueue_styles() {
wp_enqueue_style( ‘parent-style’, get_template_directory_uri() . ‘/style.css’ );
wp_enqueue_style( ‘child-style’, get_stylesheet_uri(), array( ‘parent-style’ ) );
}
As soon as you do it, your child theme becomes equal to the parent theme and now you need to start its customization.
6. Modify the font of the theme:
You can change the font of theme in an easy way to customize the website. To do so, just edit the /wp-content/themes/twentyfifteen-child/style.css file, and add this lines to it:
@import url(https://fonts.googleapis.com/css?family=Raleway);
body {
font-family: ‘Raleway’, sans-serif;
}
Thecomplete new style.css file will look just like this:
/*
Theme Name: Twenty Fifteen Child
Theme URI: http://the-url-where-theme/can-be-downloaded
Description: Twenty Fifteen Child Theme
Author: Guillermo Garron
Author URI: http://www.garron.me
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: responsive, blog
Text Domain: twenty-fifteen-child
*/
@import url(https://fonts.googleapis.com/css?family=Raleway);
body {
font-family: ‘Raleway’, sans-serif;
}
The added line will import a new font from Google fonts and Raleway in this case. Rest of the lines will direct the browser to make use of Raleway in place of Noto that is default for the theme.
Important Points to remember:
· When You should use a child theme for WordPress:
It totally depends on your requirements. In general, you can use a child theme when you have to add new functions to your websites constantly. Also, when you have to make a lot of modifications to your WordPress website such as the Entire color, contents, themes, then you should use a child theme.
· Choosing the right directory:
Following some tips will make your work easier . Theme creators need to learn the difference between get_stylesheet_directory() and get_template_directory() and creating pluggable functions.
While adding assets making use of available functions, you must always remember that get_template_ family of functions will point to the directory of the parent theme at all the times and other hand, get_stylesheet_ family of functions will indicate to the child theme’s directory always.
In the given example, the first link gets its image from the parent’s them and Second one obtains it from child theme. You can take decision to use any one of them.
The upside to make use of get_stylesheet_directory_uri() is that child theme developers can utilize their own image easily by creating in appropriate location. Additionally, if the image is not found in child theme, it will not be displayed.The main cause of it is that if a child is active to acquire _stylesheet_directory_uri() function doesn’t look into( and is not aware of ) which file you will load. That is why, it will not verify its existence and will turn back the URI for child theme.
· Flexible functions:
You must make use of free WordPress plugins while creating child theme as it will enable you to annul the functions in the parent theme. This includes closing your functions in function_exists() checks. For Example, if you create a function for a customized post meta display named my_meta(). Child theme can’t modify this theme for the reason that it can’t be defined twice. For its solution, create this function only when it has not been defined.
EndNote:
A WordPress child theme can be created in a few simple steps and WordPress users don’t need to learn special programming skills to do this. This post help bloggers to learn the art of creating a WordPress child theme in an easy way.
Comments are closed.