How to create a subtheme in WordPress
If you want to make modifications to the code of your theme and you don't want to lose these modifications when you upgrade the theme, you can create a subtheme/child theme, make it the default one and perform the modifications to the subtheme. This way you don't have to make the same modifications each time you upgrade the theme.
Let's assume that you want to create a subtheme of a theme called Example Theme and that the respective directory of that theme on your WordPress hosting account is labeled example_theme. We'll also assume that your WordPress is installed directly in the public_html folder on your account, so that the path to the theme's folder will be public_html/wp-content/themes/example_theme. To create a child theme you need to do the following things:
- In the themes folder on your account (e.g. public_html/wp-content/themes) create a new folder for the child theme (e.g. public_html/wp-content/themes/example_theme_subtheme).
- Create a new file called style.css, edit it and at the top put the following:/* Theme Name: Example Theme Subtheme Theme URI: http://yourtheme.com/ Description: something Author: your name Author URI: http://yourdomain.com/ Template: example_theme Version: 1.0 */ @import url("../example_theme/style.css");
The values are just examples, you can replace them with your own information. The only required values that you need to provide are for Theme Name and Template. You can put any name that you want. For Template type the name of the folder of the parent theme; in our example that's example_theme. The import command is for importing the style.css file of the original parent theme; in this way the subtheme will look like the parent theme.
- Upload the newly created style.css file on your hosting account in the folder of the subtheme (e.g. public_html/wp-content/themes/example_theme_subtheme).
- Log in to the admin panel of your WordPress and change the theme to the newly created subtheme.
You can edit the style.css file of the subtheme if you want to make any modifications to the style of the theme. It will overwrite the parent theme. A theme consists of many other files. The subtheme uses the files of the original parent theme. If you want to make a modification to any of the other files, copy it from the folder of the parent theme and paste it in the folder of the subtheme; then just make the change in the copied file.
For some more details you can also read the tutorial on creating a child theme in WordPress. On a similar subject you may also find useful the tutorial on keeping the modifications to the code of your WordPress theme when upgrading it.
Was this answer helpful?
- How to change the font family, size and color of post and page content in WordPress
- How to change the font family, size and color of post and page titles in WordPress
- How to manage the network admin panel in WordPress multisite
- How to change the font family, size and color of text in WordPress
- How to change the font family, size and color of comments in WordPress