Create a WordPress Child Theme - Step by Step Instructions
WordPress allows the extension and adaptation of themes with child themes. A child theme is a theme that inherits the functionality and design of the parent theme. It enables the addition of new features or the simple change of the parent theme.
The main advantage is that the adjustments in the child theme can be made without changing the files of the parent theme. This means that your own modifications are not lost when the parent theme is updated. Updates in WordPress usually replace all files in the theme.
The child theme itself can remain very slim because it only contains the code for the modifications themselves. In the following step by step guide I will show you how you can create your own child theme.
1) Create child theme folder
As an example we create a child theme for the standard TwentySixteen theme. The name of the child theme should be Theme Killer .
The first thing you will do is create a new folder on your computer. This should contain all files of the child theme. I recommend adhering to the common WordPress conventions, ie using only lowercase letters and separating words with hyphens.
We are therefore creating a new folder named theme-coder
for our child theme.
2) Create the style.css of the child theme
The child theme first needs a style.css
file, which you can create in the new folder. Design adjustments to the parent theme can later be made in the file using CSS - for example, changing colors, typography or spacing.
The style.css also contains all the information for your new theme, such as the name, description, version number and author. This information will later be displayed in the WordPress backend. Therefore copy the following text at the beginning of the style.css.
It is important to specify the template parameter. We are telling WordPress that this is a child theme. Please note that the name of the folder of the parent theme is used here. So twentysixteen
, not twenty sixteen.
3) Create functions.php of the child theme
In the next step we create another file called functions.php
addition to the style.css
WordPress automatically loads this before the functions.php of the parent theme and thus allows the functionality to be overwritten or expanded with your own functions or code snippets. The file remains empty for now, but we will change that in the next step by creating our own function.
4) Load the style.css of the parent theme
WordPress automatically loads the style.css of the active theme. Thus the style.css of the child theme is loaded. WordPress does not load the style.css of the parent theme if it is no longer the active theme.
In most cases, we don't want to develop a completely new stylesheet for our theme, but rather take the original design and just change something. Therefore, the child theme must ensure that the style.css of the parent theme continues to be loaded.
This used to be solved with an @import rule in the style.css of the child theme. However, this approach is no longer up-to-date because it is slower and does not use the standard WordPress functions.
We are therefore creating a new function to integrate the style.css of the parent theme. To do this, copy the following code into the functions.php of your child theme.
We use the standard procedure with wp_enqueue_style for integrating CSS and JS files. With the function get_template_directory_uri
we get the path to the folder of the parent theme.
5) Install child theme
The creation of the child theme is now complete. In the last step we install the new theme in WordPress.
One option for installation is uploading to the web server using FTP. The child theme has to be copied into the WordPress theme folder like any other theme.
- Root directory (www)
- wp-content
- themes (directory for all installed themes)
- twentysixteen (folder of our parent theme)
- theme-coder (our new child theme)
- themes (directory for all installed themes)
- wp-content
A second possibility is the direct installation in the WordPress backend. To do this, the child theme folder must first be packed into a theme-coder.zip
file. The .zip file can then be selected under Design> Themes> Add> Upload theme in the WordPress backend to install the child theme.
Conclusion
The child theme can now be activated and used. PHP code snippets can now easily be inserted into functions.php, which style.css can be used for style changes. Modifications are no longer lost when updating the parent theme.
Update: Series on Child Themes
All the possibilities that you can use with a child theme to adapt your theme are now presented in a small series of articles.
THANK YOU VERY MUCH!
THIS POST HAS HELPED ME A LOT! BUT I HAVE ANOTHER QUESTION: I HAVE INSTALLED WORDPRESS VIA ARTFILES WEBMAIL BECAUSE MY HOMEPAGE IS HOSTED THERE! BUT I HAVE NO IDEA HOW TO CREATE A .php OR .css FILE, SO I CANNOT UPLOAD THE CHILD THEME
The files and the child theme folder can be created on the computer and then uploaded to the / wp-content / themes / folder via FTP. For this you need FTP access data, which the web host normally provides.
It is even easier to compress the child theme folder into a .ZIP file. This can be used for installation directly in the WordPress backend under Design> Themes> Add> Upload theme.
But: If all of this seems too complicated, there are also easier ways to get a child theme. In the WordPress plugin directory there are also plugins available to create child themes directly in the WordPress backend. e.g. https://de.wordpress.org/plugins/one-click-child-theme/
Hope that helps you.
LG,
Brian
Great tip. And everything worked straight away. Thanks for that 🙂
Good start - but my parent theme had a total of 3 css files in use. But at least this article and also https://codex.wordpress.org/Child_Themes helped me to get it done 🙂
Hello Stephan,
Thank you, I'm happy.
This is due to the parent theme and how the CSS files are loaded there. Best practice is actually that only the style.css of the parent theme has to be loaded by the child theme, no further CSS files.
Whether stylesheets are integrated by the child or parent theme can be recognized by the functions used. See also this post: https://themekiller.me/2017/01/24/die-wichtsten-url-und-dateipfad-funktion-fuer-wordpress-theme-entwickler-im-ueberblick/
Many Greetings,
Brian
Super thank you !
For me, the signs are Bohemian villages, but it works!
Well explained.
Thank you very much, I'm glad 🙂