WordPress函数get_theme_root()

描述:

获取主题themes文件夹的绝对目录路径

用法:

<?php get_theme_root(); ?>

参数:

$stylesheet_or_template

(string) (必填) 主题的样式表或模板名称.

默认值: None

示例:

<?php
function display_themes_subdirs_count_info()
  $theme_root = get_theme_root();
  $files_array = glob("$theme_root/*", GLOB_ONLYDIR);
  echo "There are " . count($files_array) . " subdirectories in the " . $theme_root . " directory"; 
}
?>

源文件:

/**
 * Retrieve path to themes directory.
 *
 * Does not have trailing slash.
 *
 * @since 1.5.0
 *
 * @global array $wp_theme_directories
 *
 * @param string $stylesheet_or_template The stylesheet or template name of the theme
 * @return string Theme path.
 */
function get_theme_root( $stylesheet_or_template = false ) {
	global $wp_theme_directories;

	if ( $stylesheet_or_template && $theme_root = get_raw_theme_root( $stylesheet_or_template ) ) {
		// Always prepend WP_CONTENT_DIR unless the root currently registered as a theme directory.
		// This gives relative theme roots the benefit of the doubt when things go haywire.
		if ( ! in_array( $theme_root, (array) $wp_theme_directories ) )
			$theme_root = WP_CONTENT_DIR . $theme_root;
	} else {
		$theme_root = WP_CONTENT_DIR . '/themes';
	}

	/**
	 * Filter the absolute path to the themes directory.
	 *
	 * @since 1.5.0
	 *
	 * @param string $theme_root Absolute path to themes directory.
	 */
	return apply_filters( 'theme_root', $theme_root );
}