Tag Archives: child theme

Child Theme Wizard – Version 1.1 released

wizard

I’ve released a new version of my popular Child Theme Wizard plugin today. Everything remains the same, except for one thing: the parent theme is no longer loaded via CSS, it’s now being loaded via PHP. Let me explain why.

When I wrote this little tool in 2014, the best practice to create a child theme was to load the parent’s style sheet via CSS. This was done with an @import statement, like this:

While this approach works just fine, this is no longer regarded as the best approach to the puzzle. That’s because the parent theme’s full path is hard coded into your child theme, and should the parent theme ever change it’s folder name, your child theme would stop working.

There’s a better way to get the same thing done by loading the parent style sheet via PHP in the functions.php file. Here’s how it’s done:

So that’s what the update does: switch from the older way of loading the parent theme to the new one. There. Keeping up with the times and all 🙂

Download Child Theme Wizard

You can download the plugin from the official WordPress Plugin repository, or take a look at the source code on GitHub. Enjoy!

  • https://wordpress.org/plugins/child-theme-wizard/
  • https://github.com/versluis/Child-Theme-Wizard

How to test if your theme is a Child Theme

wordpress-icon
You may need to know which of your themes are child themes, or in fact if the current theme you’re using is a parent or a child theme.

Here’s how you can test both options.

The following code snippet will iterate through all themes that are currently installed and displays the title and if it is a child theme or not:

First we grab an array of installed themes using wp_get_themes(). Each item is an object of WP_Theme and has many helpful methods. Its method parent() will return false for non-child themes, or the parent theme if it is in fact a child theme.

Next we test if the output is false, and if so print a status accordingly.

Is the current theme a child theme?

Here’s how we can check it:

Here we employ very much the same, except for the first line in which we grab only a single object which defaults to the current theme.

Check out all the other bits of info this class can provide.

  • https://codex.wordpress.org/Function_Reference/wp_get_theme
  • https://codex.wordpress.org/Function_Reference/wp_get_themes
  • https://codex.wordpress.org/Class_Reference/WP_Theme
  • https://codex.wordpress.org/Child_Themes