The rise of new technologies and the massive use of social networks as a communication element for users and brands is a fact that has revolutionized the way we interact. Despite this, these channels tend to be the spaces through which dialogues are generated. Normally it is through the formation of blog platforms or websites where these dialogues find arguments that are supported.
Having a digital presence through a blog is a great asset for users and companies seeking to consolidate their image on a digital level. And thanks to tools like WordPress, this has been simplified, making it possible for anyone to generate a good content space. The problem comes when working on a template and it is modified by a routine update. How to correct this problem?
What are Child Themes?
Imagine that you invested a few hours working and modifying a WordPress template to your liking. After a few months from your desktop you can check a new update to the template. After this, you will discover that part of the design that took you so many hours to invest, has been modified. Although this is nothing more than a small example of change. In cases like these you can use child themes.
Child themes are, as their name suggests, daughter templates of a parent dependent theme that maintains the original functionality of the latter. The difference with the child template is that although it acquires all the elements of the parent theme, it is not updated directly. That is, if you work on a website with daughter and father templates, only the parent template is updated.
What function do Child Themes have on a website?
There are times when we develop a good web design but, as in the previous example, installing an update will mess up one of our modules. It may also be that you want to work independently on the theme code to make some modification to its structure. For these cases it is interesting to use a daughter template.
Some complementary utilities would be:
-Add lines of code to work on the operation of an external application.
-Modify aspects of the page’s CSS.
Steps to create a child template
To explain how to create a child theme, let’s start with a base main template. For example, let’s think that we are working on our website from the TwentySeventeen theme. Therefore, the steps we must follow will be the following:
1-Assemble the template on our WordPress website. From the platform desktop we activate the theme that we are going to use as a basis on which to build our space on the network.
2-Next we must access the FTP, that is, the place where our website is hosted, and enter the “wp-content/themes” folder. Inside is where all the templates that we have installed are saved. We will therefore see TwentySeventeen there.
Well, this is where we are going to start creating our child theme. To do this, we are going to create a new folder that we will call, for example, “twentyseventeen-child”.
3-We go in and create two files. On the one hand we are going to create a “style.css” file, and on the other hand “functions.php”. It is possible to create these files from a “txt” that we rename with its corresponding extensions.
3.1-Taking into account the style of the parent template that we are using (TwentySeventeen), we must copy the following code into our new “style.css”:
Theme URI: http://misitio.com/twenty-seventeen-child/
Description: Child theme for various modifications
Author: My name
Author URI: http://mysite.com
Template: twentyseventeen
Version: 1.0.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Tags: light, dark, two-columns, right-sidebar, responsive-layout, accessibility-ready Text Domain: twenty-seventeen-child
*/
3.2-For the functions.php we will copy the code below:
$parent_style = ‘twentyseventeen-style’;
$child_style = ‘twentyseventeen-child-style’;
wp_enqueue_style( $parent_style,
get_template_directory_uri() . ‘/style.css’ );
wp_enqueue_style( $child_style,
get_stylesheet_directory_uri() . ‘/style.css’,
array( $parent_style ),
wp_get_theme()->get(‘Version’)
);
}
add_action( ‘wp_enqueue_scripts’, ‘enqueue_styles_child_theme’ );
4-From here we can load the child theme as an independent element from the WordPress desktop. It is important to remember that all the modifications we make will not affect the parent template, but will be modified in the daughter.
Did you like this article? Rate it!
More related articles
This post is also available in: