wp_get_theme

函数
wp_get_theme ( $stylesheet = '', $theme_root = '' )
参数
  • (string) $stylesheet Optional. Directory name for the theme. Defaults to active theme.
    Required:
    Default: (empty)
  • (string) $theme_root Optional. Absolute path of the theme root to look in. If not specified, get_raw_theme_root() is used to calculate the theme root for the $stylesheet provided (or active theme).
    Required:
    Default: (empty)
返回值
  • (WP_Theme) Theme object. Be sure to check the object's exists() method if you need to confirm the theme's existence.
定义位置
相关方法
wp_get_themesget_themeget_themeswp_get_theme_errorget_the_time
引入
3.4.0
弃用
-

wp_get_theme: 这个函数为一个给定的主题检索一个主题对象。它接受一个参数–主题的名称。如果找到该主题,它将返回一个WP_Theme对象,如果该主题不存在,则返回null。

获取一个主题的WP_Theme对象。

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, true ) ) {
			$theme_root = WP_CONTENT_DIR . $theme_root;
		}
	}

	return new WP_Theme( $stylesheet, $theme_root );
}

常见问题

FAQs
查看更多 >