当前浏览:首页 / WordPress函数 / get_theme_root()

get_theme_root( string $stylesheet_or_template = '' )

检索主题目录的路径

root

theme 主题more...


描述

没有尾随斜杠。


参数

$stylesheet_or_template

(string)(可选) 主题的样式表或模板名称。默认情况下是利用主主题根。

默认值: ''


返回

(string) 主题目录路径。



源码

查看源码 官方文档


更新日志

版本描述
1.5.0开始引入

使用示例

  • 示例1

    主题目录中的子目录数
    下面的函数通知主题目录中子目录的数量。请注意,这不一定与WordPress识别的主题数量匹配。

    <?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"; 
    }
    ?>
    

    示例输出:

    There are 5 subdirectories in the /home/user/public_html/wp-content/themes directory.