WordPress themes are stored in /wp-content/themes. This means they are not WordPress core files; and that means we can edit them.
Uh oh! Themes update. What happens to file edits when our theme updates? They get overwritten.
How do we protect theme file edits?
Themes come in two classes:
- Parent themes
- Child themes
Parent themes consist of page template files, theme images, Javascript libraries, style sheets and other files. These files are used by WordPress to provide the frontend — public facing — look of a site.
Child themes can be created with only one file: a stylesheet. This stylesheet tells WordPress that the child has a daddy and that daddy will supply all the other files that WordPress needs for the child theme to work.
Example Parent Theme Files
Child Files
When a child theme is active, WordPress reads the theme’s stylesheet. The stylesheet has a line of text in it that tells WordPress where to look for the parent theme files.
In the image above, the line that says “Template: Genesis” tells WordPress that the parent theme is Genesis. In other words, for this example child theme, the template (parent) theme that is being used is called Genesis and the child theme’s files are to be used in preference to the parent theme’s files.
How do child themes protect theme file edits?
We can copy files from the parent theme and put them into the child theme’s folder. WordPress will use the child theme’s files in preference to the parent theme’s files.
When a parent theme has a footer.php file and a child theme has a footer.php file, WordPress will use the child theme’s footer.php. The parent theme’s footer.php file will be ignored.
Child theme files are not overwritten when its parent theme updates.
When we want to edit files in a WordPress theme, we need to:
- make a child theme
- copy files we want to edit into the child theme’s folder
- edit the child files in the child theme folder (not the parent theme).
Is there an easy way to make child themes?
We can automate child theme creation by using a plugin to automate the process. Several plugins exist to do this. We recommend Child Theme Configurator.
1 - Install The Plugin
Install Child Theme Configurator from the WordPress repository. Go to Plugins > Add New and search for the plugin.
2 - Make A Child Theme
Make a child theme by going to Tools > Child Themes.
3 - Choose Files to Edit
Choose the files you want to edit.
There is no point duplicating all the parent theme’s files into the child theme’s folder. Only copy the files you will edit.
Leave a Reply