Over the years, WordPress has evolved from a simple blogging system to an easy-to-use CMS platform and has become ubiquitous on the web. Thanks to its popularity, many professionals have specialized in providing WordPress themes as website templates. These already include almost all the functionalities of a website and are very similar to how the final product should be, but not identical. Usually you have to make adjustments in the code to adapt the site to the corporate design, or you have to change the structure. But what about the changes when the theme is updated? This is what the child themes in WordPress are for..
If you want to prevent your changes from being overwritten when updating, you must use a child WordPress theme. WordPress child themes they are, as their name suggests, the children of a parent theme . These are tied to the parent theme so that they inherit its appearance and functions. If you make individual settings in the child WordPress theme, they are automatically overwritten in the parent theme's instructions . Therefore, the changes have no effect on the main topic. If the parent theme is updated, the changes to the child WordPress theme remain in place.
During major adjustments or updates, error messages may appear on the website. In order not to disturb users, you must activate WordPress maintenance mode..
A WordPress child theme it can have different components. In this sense, the changes and the files where they are made are decisive. However, for what WordPress child themes work correctly , there are certain files that you must create for each of them:
Why is the WordPress child theme do you need these three files?
As we've already mentioned, a WordPress child theme needs three files to function. The files have the following functions:
If you are only going to make minor changes to the theme, there are simpler solutions such as the Simple Custom CSS Plugin or the customizer integrated directly into WordPress from version 4.7.
Using a child WordPress theme has many advantages. However, it also has some drawbacks, so you have to consider whether it is worth creating an extra theme just to implement small changes to the CSS:
After explaining the functions, here we tell you how to create a functional child theme in WordPress:
Using an FTP client, such as FileZilla, connect to your server and navigate within the WordPress installation to the following folder:
tu ruta hacia la instalación de wordpress/wp-content/themes/
There you create a folder for the WordPress child theme. It is convenient to use the name of the parent theme by adding ? -Child? in the end..
Create a style.css file and add the following information in the header area using a text editor:
/* Nombre del tema: [Nombre del tema padre] Child URI del tema: [http://example.de/parent-theme/] Descripción: [Nombre del tema padre] Tema hijo Autor: [Tu nombre] URI del autor: [El URL de tu sitio web] Plantilla: [Nombre de la carpeta del tema padre] Versión: 1.0.0 Dominio de texto: [Nombre del tema padre] -child */
Replace the bracketed placeholders with your specifications. You don't have to enter all the elements; It is only mandatory to add the following two data for the WordPress child themes to work:
When the file is ready, use the FTP client to upload it to the WordPress child theme folder.
In the best case scenario, the parent theme already contains the instruction to load the stylesheet of the child WordPress theme. But not all design templates do this. Therefore, it is important to take a look at the functions of the parent theme. One of the following three scenarios applies:
If the second case occurs, function.php looks like this:
<!--?php</codesnippet--> add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' ); function my_theme_enqueue_styles() { wp_enqueue_style( 'child-style', get_stylesheet_uri(), array( 'Nombre de la hoja de estilo del tema padre'), wp_get_theme()-> get('Version') // Solo funciona si el elemento version también se especifica en el área del encabezado de la hoja de estilo ); } ?>
If the WordPress child theme needs to load both stylesheets via function.php , the code looks like this:
<!--?php</codesnippet--> function child_theme_styles() { wp_enqueue_style( 'Nombre de la hoja de estilo del tema padre', get_template_directory_uri() . '/style.css'); wp_enqueue_style( 'child-theme-css', get_stylesheet_directory_uri() .'/style.css' , array('Handle 'Nombre de la hoja de estilo del tema padre')); } add_action( 'wp_enqueue_scripts', 'child_theme_styles' ); ?>
Enter function.php in the style.css file in the child theme folder in WordPress.
Optionally, you can also place an image file with the filename screenshot.png in the WordPress child themes folder. WordPress displays this image in the background of the theme, so you can better map the template.
After creating the WordPress child theme, activate it like any other theme in the WordPress backend . To do so, simply go to the backend and select the child theme in Design> Themes .
If you have already made adjustments to the parent theme through the WordPress customizer, these changes will be lost when activating the child WordPress theme. With the Customizer Export / Import plugin, you can export the customizer settings and then import them again.
Now the WordPress child theme is completely ready for use. If you want to make changes to other template files, copy the parent theme file and save it in the child theme folder. The path must exactly match the path of the main topic. The main theme file is automatically overwritten by the file from the WordPress child themes folder.
With WordPress hosting from IONOS, you will have a specially optimized WordPress hosting platform that makes it easy for you to create your own WordPress website.