wp_get_theme() WordPress Function

The wp_get_theme() function is used to retrieve the current theme's information. This function can be used to get the name, author, version, and other information of the active theme. Additionally, this function can be used to get information about a specific theme by passing the theme's directory name as an argument.

wp_get_theme( string $stylesheet = '', string $theme_root = '' ) #

Gets a WP_Theme object for a theme.


Parameters

$stylesheet

(string)(Optional) Directory name for the theme. Defaults to active theme.

Default value: ''

$theme_root

(string)(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).

Default value: ''


Top ↑

Return

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


Top ↑

Source

File: wp-includes/theme.php

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


Top ↑

Changelog

Changelog
VersionDescription
3.4.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More