is_child_theme()WP 3.0.0

Whether a child theme is in use.

1 time — 0.00001 sec (speed of light) | 50000 times — 0.01 sec (speed of light) | PHP 7.0.8, WP 4.6

No Hooks.

Return

true|false. True if a child theme is in use, false otherwise.

Usage

is_child_theme();

Examples

0

#1 Run code for the child theme only

Suppose we are writing a theme and we only need to execute PHP code when our theme is used as a parent theme, i.e. a child theme is defined and used:

if( is_child_theme() ){
	echo 'The code is for the child themes, not the parent;
}
0

#2 Alternative detection if is child theme.

WARNING: This function uses the TEMPLATEPATH and STYLESHEETPATH constants internally. If calling from a plugin, such as during plugin activation, there’s a chance these will be undefined. It is better to use:

get_template_directory() !== get_stylesheet_directory()

Notes

  • Global. String. $wp_stylesheet_path Path to current theme's stylesheet directory.
  • Global. String. $wp_template_path Path to current theme's template directory.

Changelog

Since 3.0.0 Introduced.
Since 6.5.0 Makes use of global template variables.

is_child_theme() code WP 6.5.2

function is_child_theme() {
	global $wp_stylesheet_path, $wp_template_path;

	return $wp_stylesheet_path !== $wp_template_path;
}