WordPress at a glance

wp_get_theme() WP 1.0

Gets a WP_Theme object for a theme.

Works based on: WP_Theme()
✈ 1 time = 0.00056s = slow | 50000 times = 2.02s = fast | PHP 7.0.5, WP 4.5.2

No Hooks.

Return

WP_Theme. Theme object. Be sure to check the object's exists() method if you need to confirm the theme's existence.

Usage

wp_get_theme( $stylesheet, $theme_root );
$stylesheet(string)
Directory name for the theme. Optional.
Default: current theme
$theme_root(string)
Absolute path of the theme root to look in. Optional. If not specified, get_raw_theme_root() is used to calculate the theme root for the $stylesheet provided (or current theme).
Default: null

Notes

  • Global. Array. $wp_theme_directories

Changelog

Since 3.4.0 Introduced.

Code of wp get theme: wp-includes/theme.php WP 5.2.2

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

Related Functions

From category: Other Theme Functions

No comments
    Hello, !     Log In . Register