Should I Use A Child Theme in WordPress – No Question!

Facebooktwittergoogle_plusredditpinterestlinkedinmail

child-theme-file-structure-bigA Child Theme is the recommended way to modify a theme in WordPress.  By using a Child Theme, the parent theme is able to freely update without overwriting your changes.  Updates in WordPress are critical for not only bug fixes and feature enhancements, they often address security issues and breaking changes to the WordPress core.  You should always update your parent theme because of those concerns.  The best reference for creating a Child Theme is How to Create a Child Theme.  Of course, the best theme, in my opinion, is GeneratePress.

There are three benefits to creating a child theme: you can modify your theme directly without the chance of losing your changes, it speeds up development, and it helps you understand theme development.  Any one of these benefits makes the effort worth it.  However, all three together makes this a win-win scenario and something you should embrace.  Even if you have no planned changes, the infrastructure is readily available when you need it.

A Child Theme is one of the easier entities to create.  It consists of a directory (file folder) that resides in wp-content/themes, a style.css file, and a functions.php file which both reside inside the Child Theme directory.  That’s it!  I know, it feels like it should be harder, doesn’t it?

Open your favorite text editor, which could be anything from Sublime Text, to Brackets. or even Notepad (TextEdit on the Mac), to create a style.css file.  “The stylesheet must begin with the following stylesheet header.”  This is boilerplate code you need to modify for your specific case.

/*
 Theme Name:   Twenty Fifteen Child
 Theme URI:    http://example.com/twenty-fifteen-child/
 Description:  Twenty Fifteen Child Theme
 Author:       John Doe
 Author URI:   http://example.com
 Template:     twentyfifteen
 Version:      1.0.0
 License:      GNU General Public License v2 or later
 License URI:  http://www.gnu.org/licenses/gpl-2.0.html
 Tags:         light, dark, two-columns, right-sidebar, responsive-layout, accessibility-ready
 Text Domain:  twenty-fifteen-child
*/

 

 

Other than the Theme Name on Line #1, where you should indicate it is indeed a Child, the other necessary line is Template on Line #7, which points to the directory (file folder) of the parent.  Use the same text editor to create an empty functions.php file.  As you can see in this picture, I have appended child to the directory name  so that I can keep my sanity.  The only other structure we have not discussed is the screenshot.png.  Per the Codex:

The recommended image size is 1200×900. The screenshot will only be shown as 387×290, but the over double-sized image allows for high-resolution viewing on HiDPI displays.

Normally what I do is copy the screenshot from the parent theme and use a photo editing application like Photoshop or Gimp to change the name at the top of the screen shot to indicate that it is a Child so, again, I keep my sanity.  This screen shot will appear when you click on Appearance > Themes in the Admin Panel.  Of course, if it is the only theme without a screenshot, that is also a distinguishing factor to help you find it to activate it.

In style.css you would usually have to enqueue the stylesheet from the parent theme.  This is not required when you use GeneratePress because the Theme developer has done all the heavy lifting for you.  The stylesheet is ready for use when you activate the Child Theme you just built with an empty style.css.

Now, activate your Child Theme.  As long as your parent theme always remains in your wp-content/themes directory, you are set for any future updates the theme author is ready to throw at you!

 

 

Facebooktwittergoogle_plusredditpinterestlinkedinmail

Leave a Comment