wordpress主题信息一般包含在Style.css
文件中,包括当前主题名称、版本、开发者信息等;如果在开发中某个功能需要用到主题的信息可以通过wp_get_theme()()
函数进行获取。
wp_get_theme()( string $stylesheet = null, string $theme_root = null )
函数原型
# 获得当前主题或指定主题的信息
function wp_get_theme()( $stylesheet = null, $theme_root = null ) {
global $wp_theme_directories;
if ( empty( $stylesheet ) ) {
$stylesheet = get_stylesheet();
}
if ( empty( $theme_root ) ) {
$theme_root = get_raw_theme_root( $stylesheet );
if ( false === $theme_root ) {
$theme_root = WP_CONTENT_DIR . '/themes';
} elseif ( ! in_array( $theme_root, (array) $wp_theme_directories ) ) {
$theme_root = WP_CONTENT_DIR . $theme_root;
}
}
return new WP_Theme( $stylesheet, $theme_root );
}
函数参数
- $stylesheet (string) (可选) 指定的主题名,默认当前主题。默认值: 空
- $theme_root (string) (可选) 主题的绝对路径,如果为空, 则使用get_raw_theme_root()函数得到的路径 (默认当前主题);默认值: 空;返回值(WP_Theme) 主题对象。 如果不知道主题是否存在,请使用主题对象的exists()方法判断。
返回值
- $stylesheet (string) (可选) 指定的主题名,默认当前主题。默认值: 空
- $theme_root (string) (可选) 主题的绝对路径,如果为空, 则使用get_raw_theme_root()函数得到的路径 (默认当前主题);默认值: 空;返回值(WP_Theme) 主题对象。 如果不知道主题是否存在,请使用主题对象的exists()方法判断。
返回值
返回的为WP_Theme对象类型,通过->进行使用
- [Name]:主题名称
- [ThemeURI]:主题链接
- [Description]:主题介绍
- [Author]:作者名称
- [AuthorURI]:作者主页链接
- [Version]:主题版本
- [Template]:父主题的文件夹名称,子主题中使用
- [Status]:主题状态
- [Tags]:标签
- [TextDomain]:主题中用于翻译目的的文本域
- [DomainPath]:主题翻译文件路径
- [RequiresWP]:要求wordpress的版本
- [RequiresPHP]:要求php的版本
- [UpdateURI]:更新链接