Add Child Theme Support to Any WordPress Theme

photo credit: Leeroy
photo credit: Leeroy

If you’re a developer, you may take for granted how easy it is for you to create a child theme for storing customizations separate from the parent theme. This one seemingly simple task can pose a significant hurdle for your average WordPress user. Without understanding the best practice of creating a child theme, users resort to cramming all changes into the active theme. This puts them in a vulnerable position when security updates are available but they cannot update without overwriting their changes.

Matt Gibbs, lead developer of FacetWP, has created a little project to help users with creating child themes. “Use Child Theme” is a simple drop-in PHP class that theme developers can use to alert their users to activate a child theme and automatically create one for them.

“Normally, themes have to point users to a child theme documentation page or link to a pre-built child theme zip,” Gibbs said. “Most users don’t even bother.”

Gibbs said the Use Child Theme project was built to make it easy for theme authors to support it. The project was also an offshoot of his experiences supporting FacetWP.

“I do a lot of plugin support, and this issue keeps coming up over and over,” Gibbs said. “Users are on super old theme versions and they’re afraid to upgrade because they’ve modified the parent theme at one point, and don’t want to lose changes.”

The idea behind Use Child Theme is to automatically create a child theme for someone who otherwise might not know how to create one. It’s not a plugin but rather a tool that theme developers can opt to include with just one line in functions.php:

include( dirname( __FILE__ ) . '/use-child-theme.php' );

WordPress theme developers, is this a method you would consider using to prompt users to activate a child theme? Or would you rather rely on links to documentation and/or a download link to a pre-built child theme?

14 Comments


  1. Hi

    There is no reason for any website owner to stay on a old theme when customisations are in place. There are two pretty good programs to find all their customisations by doing a compare old theme original against old theme modified and redo them to the new theme release by a compare old theme modified against new theme original.

    They are called winmerge and beyond compare. I use them on a daily base to compare code of themes and plugins and redo changes.

    Best regards, Neo

    Report


    1. If only there was a way to downvote comments here :( this idea is like -1000.

      At the min, use git. Will not solve the fundamental problem of upgrading the master theme with ease, but at least you will be able to automate the merge process.

      Report


      1. If only there was a way to downvote comments here :( this idea is like -1000.

        Clearly you miss Emoji reaction.

        Report


  2. Great idea but this would not pass the WordPress TRT requirements so on that note, no I would not use it in my themes.

    I can only see this working for non WPORG themes!

    Report


  3. I had to try this out, so I added the code to one of my themes and tried it out…long story short, this is a very cool option to add to themes. I know there are a lot of people who are new to WordPress, especially theme modifications, let alone creating a child theme (which can be challenging). Normally with my premium themes I include a premade child theme, but for the free versions, we cannot add child themes to the install package.

    On my first try, I clicked on activate child theme and sure enough it literally created a child theme and activated it at the same time. One thing I did was modify the screenshot path for copying a custom child theme screenshot located in the parent theme’s image folder….it worked!

    There is one item of thought that would be an awesome addon would be to import the parent theme Customizer options should a user already have settings already set like colours, blog style, etc.

    Overall, this is a very nice function to offer newbies by simply clicking on a link to create and activate a child theme.

    Report


  4. So, in order to avoid polluting the parent theme, we put a new file in there and modify `functions.php` there too.

    Or have I missed something?

    Report


  5. Reached out to Matt Gibbs a long, long time ago because I love everything he does. Totally gonna hit him up again! FWP PWNZ.

    Report


    1. @Gunnar That plugin also looks cool! It’s good to see more developers addressing this problem. My custom theme has a child theme generator built in. When the theme is activated, it checks if parent or child. Throws a dismissable for user to deactivate parent, activate child. Then, run the child generator if child ! exists. Simple solution. I like Matt’s 178-line class tho.

      Report


  6. Child theme is an attractive concept and apart from WordPress, other enterprise web content management services like Sitefinity CMS, Drupal etc also follows this concept with the name of sub-theme, however no one is as good as WordPress. Child theme is a theme inherited from a build theme with additional features added by a company to suit their business requirements. WordPress allows to reuse this child theme with different websites and also can be shared to the community. The concept saves time and cost of buying multiple themes for different websites.
    Thanks for sharing useful information to help developers to define a child theme effortlessly.

    Report

Comments are closed.