how to make a child theme

How to Create a Child Theme in WordPress

We start to tell you how to create a child theme in WordPress. If you have the skills of php, CSS and HTML or you have created webpages and worked with WordPress, this article is for you.

Child theme: why should you use it?

When you are creating a website using WordPress, often use a child theme (CT). May be you know how to make a child theme. If the parent theme is updated, you will save all the necessary settings. But if you will change files style.css or functions.php, all changes will be deleted after the update.

Perhaps you will also be interested in our article on How to Display Code in WordPress.

If you want to avoid site mistakes and have no difficulties with loading webpages in the browser, the theme needs to be updated. Setting up child themes allows you to practice as webdeveloper. In a child theme you control functions and ignore other files. It is easier to work with a child theme, than with a parent theme (PT). All the necessary information will be known too, when you will come back to coding.

add child theme wordpress

Two ways to get a child theme

1) The first way: for website developers, who have FTP-access

It’s easy. The file and folder must be created by you. Now we will work with the parent Customizr theme. It will help to create your own CP.

  1. First of all you need to connect to the server. Use the app as FTP-client. Then you need to create a folder where the theme. Name can be any. Do not use spaces or special characters, when you name a child theme.
  2. Secondly, the style file must be created by you in this folder. The code should be placed in this file. Name parameter of the parent template must be written as ‘customizr’. It is forbidden to use capital letters. Otherwise you may have problems.
/*
 Theme Name:     Customizr Child
 Theme URI:      http://mysite.com/
 Description:    My description
 Author:         Me
 Author URI:     http://mysite.com/
 Template:       customizr
 Version:        1.0.0
*/

 

2) The second way: beginners can use a special plugin

If you are setting up a theme first time, it is better to use the WordPress child theme plugin. You don’t have to encode anything or transfer files.

  1. Install the Childify me (it is plugin). It should be downloaded before usage.
  2. In the section ‘Appearance’, select the subdivision ‘Customize’. The plugin will add a link in the text description’s footer.
  3. You should click on the Childify Me.
  4. Select a name for the child theme.
  5. If you want to activate the theme, select the section ‘Appearance’ and click on ‘themes’. You’re done!

How to change the functionality of a parent theme by using a child theme

Child theme overwriting algorithm

WP checks all path/class-files.php if the child theme was created before. If a matches are found, the paths and files of the CT are used. They transform the parent theme. This does not happen in one case only. File functions.php is a supplement and it is run before PT functions.php.

If you made a new index.php template in child theme, index.php in the parent theme will be replaced too.

Additional function

File functions.php in the CT will be run before the corresponding PT-file. You can use this when you want to change the source files.

The system will work like this if the developer makes special changes. It is called pluggable (or additional) function. Where you are trying to install child theme WordPress, It can be useful.

If the theme is plugged, it should have features of the functions.php file as written below:

if( ! function_exists('name_of_function') ) {
function name_of_function( $params ) {
// do some stuff with the $params }
}<br>

 

WordPress child theme development helps you replace all functions declared in parents. You have this ability, because the WordPress algorithms will find the following functions in parent theme and they already exist there. So program just skip them (it works if the function_exists() condition is declared).

Let’s illustrate that process for better understanding.
Most of WP-themes have quite simple code structure. The basic is:

  • style.css
  • functions.php
  • obligate templates of theme containing elements suchlike index, header, footer, comments etc.

Other parts of code frequently organized in a folder tree and get started with /inc or /includes.

For instance the task is to transform the inc/class-content-slider.php file. You should copy and past the file class-content-slider.php in a special folder inc/ that need to be created previously. Important thing is that the path or the file looks like to previous. After doing that you can customize CT the way you need and it’ll change the PT file.

To transform a WP-theme it would be better to use the hooks tools instead of editing core files.

1 Star2 Stars3 Stars4 Stars5 Stars (5.00 / 5, votes: 1)
Loading...
Comments are closed.