+1 760-822-2156

A couple of good reasons to create a WordPress child theme for your WordPress site are if you update the theme, all customizations like CSS and custom functions will likely be lost because these files will be overwritten. The other reason is that development is usually faster because you don’t have to search through a large style sheet to find your custom CSS when it needs to be modified and you will know what CSS and functions you added in case you break something.

Before creating a child theme, be sure to check your theme to see if the developer might have created a child theme. If so, great, go ahead and use it. Otherwise, let’s get started. As always, be sure at the very least to back up your wp-content directory before making changes to your site.

Creating the WordPress Child Theme

WordPress Child ThemeFirst of all, you will want to do is create a directory in the wp-content/themes directory with the name of the parent theme then a hyphen and the word child e.g., twentysixteen-child. Even though this naming structure is not required, it does make it easier for you and anyone else working on the site to know what theme to edit or use.

The next step is to create the style sheet for your child theme. Create a new file in your favorite text editor called “style.css”. I usually copy the header from the style sheet of the parent (the part at the beginning of the file that starts with /* and ends at */) and then edit that file. Add the Template: parentname line and the @import line. Edit the theme name to show it as the child theme. You can edit the other lines if you wish.

The important items are the template line and the @import line. The template needs to be spelled exactly like the directory name of the parent. The @import line brings in the stylesheet of the parent and then any changes made on this stylesheet will override similar styles on the parent stylesheet. Be sure to use the exact capitalization for the path to the parent stylesheet. Upload this file to your child directory.

WordPress Best Practice

The best option which is the official WordPress method is to add a function to the functions.php file that will enqueue your styles. To do this, create a new file in the WordPress child theme directory called “functions.php”. In that file add the following code:

Upload this file into your WordPress child theme directory. Don’t forget to edit the style.css file to remove or comment out the @import line if you use this function. Setting up your child theme this way ensures you are following the best practices for WordPress.

The last step is to activate the new theme in the Appearance > Themes menu. If all goes well, you will see the child theme in there. If you wish, you can copy the screenshot file from the parent to the child theme so it is not a blank square. I like to edit the file with Photoshop so that it is clear that it is clearly different from the parent. Happy styling!