函数文档

wp_set_template_globals()

💡 云策文档标注

概述

wp_set_template_globals() 是一个 WordPress 函数,用于设置模板加载所需的全局变量。它初始化 $wp_stylesheet_path 和 $wp_template_path 变量,分别指向活动主题的样式表目录和模板目录。

关键要点

  • 函数定义在 wp-includes/theme.php 中,从 WordPress 6.5.0 版本引入。
  • 通过调用 get_stylesheet_directory() 和 get_template_directory() 来获取路径,并赋值给全局变量。
  • 主要用于支持主题切换和模板定位功能,如被 switch_theme() 和 locate_template() 调用。

📄 原文内容

Set up the globals used for template loading.

Source

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

	$wp_stylesheet_path = get_stylesheet_directory();
	$wp_template_path   = get_template_directory();
}

Changelog

Version Description
6.5.0 Introduced.