函数文档

wp_templating_constants()

💡 云策文档标注

概述

wp_templating_constants() 函数定义了与 WordPress 模板相关的常量,包括已弃用的模板路径常量和默认主题常量。这些常量主要用于主题开发中获取文件系统路径和设置默认主题。

关键要点

  • 定义了 TEMPLATEPATH 常量,表示当前活动模板目录的文件系统路径,但自 6.4.0 版本起已弃用,建议使用 get_template_directory() 函数替代。
  • 定义了 STYLESHEETPATH 常量,表示当前活动模板样式表目录的文件系统路径,同样自 6.4.0 版本起已弃用,建议使用 get_stylesheet_directory() 函数替代。
  • 定义了 WP_DEFAULT_THEME 常量,用于指定此安装的默认主题 slug,在安装新站点时作为默认主题,并在活动主题不存在时作为后备。

注意事项

  • TEMPLATEPATH 和 STYLESHEETPATH 常量已弃用,开发者应迁移到相应的函数以避免兼容性问题。
  • WP_DEFAULT_THEME 常量仅在未定义时设置,默认值为 'twentytwentyfive',开发者可根据需要覆盖此值。

📄 原文内容

Defines templating-related WordPress constants.

Source

function wp_templating_constants() {
	/**
	 * Filesystem path to the current active template directory.
	 *
	 * @since 1.5.0
	 * @deprecated 6.4.0 Use get_template_directory() instead.
	 * @see get_template_directory()
	 */
	define( 'TEMPLATEPATH', get_template_directory() );

	/**
	 * Filesystem path to the current active template stylesheet directory.
	 *
	 * @since 2.1.0
	 * @deprecated 6.4.0 Use get_stylesheet_directory() instead.
	 * @see get_stylesheet_directory()
	 */
	define( 'STYLESHEETPATH', get_stylesheet_directory() );

	/**
	 * Slug of the default theme for this installation.
	 * Used as the default theme when installing new sites.
	 * It will be used as the fallback if the active theme doesn't exist.
	 *
	 * @since 3.0.0
	 *
	 * @see WP_Theme::get_core_default_theme()
	 */
	if ( ! defined( 'WP_DEFAULT_THEME' ) ) {
		define( 'WP_DEFAULT_THEME', 'twentytwentyfive' );
	}
}

Changelog

Version Description
3.0.0 Introduced.