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

Jay is the CEO and founder of WP Hosting, a boutique style managed WordPress hosting and support service. He has been working with Plesk since version 9 and is a qualified Parallels Automation Professional. In his spare time he likes to develop iOS apps and WordPress plugins, or draw on tablet devices. He blogs about his coding journey at http://wpguru.co.uk and http://pinkstone.co.uk.

Add your voice!