函数文档

is_child_theme()

💡 云策文档标注

概述

is_child_theme() 是一个 WordPress 函数,用于检测当前是否正在使用子主题。它通过比较全局变量 $wp_stylesheet_path 和 $wp_template_path 来判断,返回布尔值。

关键要点

  • 函数返回布尔值:true 表示正在使用子主题,false 表示未使用子主题。
  • 内部实现基于全局变量 $wp_stylesheet_path 和 $wp_template_path 的比较。
  • 在插件中调用时需注意,可能因 TEMPLATEPATH 和 STYLESHEETPATH 常量未定义而导致问题,建议使用 get_template_directory() !== get_stylesheet_directory() 替代。

注意事项

在插件激活等场景中,TEMPLATEPATH 和 STYLESHEETPATH 常量可能未定义,使用 get_template_directory() 和 get_stylesheet_directory() 更安全。


📄 原文内容

Whether a child theme is in use.

Return

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

Source

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

	return $wp_stylesheet_path !== $wp_template_path;
}

Changelog

Version Description
6.5.0 Makes use of global template variables.
3.0.0 Introduced.

User Contributed Notes