get_theme_roots()
云策文档标注
概述
get_theme_roots() 函数用于检索主题根目录路径。它返回一个数组或字符串,具体取决于所有主题是否共享同一根目录。
关键要点
- 返回类型:数组或字符串,数组以模板/样式表为键,字符串表示所有主题共享同一根目录
- 主题目录名称格式:不带尾部斜杠但带前导斜杠
- 引入版本:WordPress 2.9.0
- 相关函数:search_theme_directories()、get_raw_theme_root() 等
代码示例
echo get_theme_roots();
// 如果主题目录位于 /home/www/wp-content/themes/,输出为 "/themes"
原文内容
Retrieves theme roots.
Source
function get_theme_roots() {
global $wp_theme_directories;
if ( ! is_array( $wp_theme_directories ) || count( $wp_theme_directories ) <= 1 ) {
return '/themes';
}
$theme_roots = get_site_transient( 'theme_roots' );
if ( false === $theme_roots ) {
search_theme_directories( true ); // Regenerate the transient.
$theme_roots = get_site_transient( 'theme_roots' );
}
return $theme_roots;
}
Changelog
| Version | Description |
|---|---|
| 2.9.0 | Introduced. |
Skip to note 2 content
Codex
Basic Example
echo get_theme_roots();If your themes directory is located at /home/www/wp-content/themes/, the above echo statement will output “/themes”.