描述:
获取主题信息
用法:
<?php $theme = wp_get_theme( $stylesheet, $theme_root ); ?>
参数:
$stylesheet
(string) (可选) 主题的目录名。默认为当前主题。
默认值: Null
$theme_root
(string) (可选) 要查看的主题根的绝对路径。如果未指定,将使用get_raw_theme_root()返回的值。
默认值: Null
示例:
显示当前激活的主题的名称。
<?php
echo wp_get_theme();
?>
显示已安装主题的名称。
<?php
$my_theme = wp_get_theme( 'twentyten' );
if ( $my_theme->exists() )
echo $my_theme;
?>
显示当前主题的版本
<?php
$my_theme = wp_get_theme();
echo $my_theme->get( 'Name' ) . " is version " . $my_theme->get( 'Version' );
?>
显示当前主题的作者URL
<?php
$my_theme = wp_get_theme();
echo $my_theme->get( 'AuthorURI' );
?>
显示主题的URL和TextDomain
<?php
$my_theme = wp_get_theme();
echo $my_theme->get( 'TextDomain' );
echo $my_theme->get( 'ThemeURI' );
?>
源文件:
function wp_get_theme( $stylesheet = '', $theme_root = '' ) {
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 );
}