获取主题的WP_Theme对象。
原型
wp_get_theme( string $stylesheet = null, string $theme_root = null )
参数
$stylesheet
(string)
(Optional)
主题的目录名称。可选的。默认为当前主题。
$theme_root
(string)
(Optional)
要查看的主题根的绝对路径。可选。如果未指定,则使用get_raw_theme_root()计算所提供的$ stylesheet(或当前主题)的主题根。
返回值
(WP_Theme)
主题对象。如果需要确认主题的存在,请务必检查对象的exists()方法。
源文件
路径:wp-includes/theme.php
<?php
...
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 );
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/wp_get_theme/