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

Gets a WP_Theme object for a theme.


Description Description


Parameters Parameters

$stylesheet

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

Default value: ''

$theme_root

(string) (Optional) 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 value: ''


Top ↑

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

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

Top ↑

Changelog Changelog

Changelog
Version Description
3.4.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 2 content
    Contributed by tazotodua

    Result:

    object(WP_Theme)[916]
      public 'update' => boolean false
      private 'theme_root' => string 'home/path/wp-content/themes' (length=77)
      private 'headers' => 
        array (size=11)
          'Name' => string 'mytheme' (length=7)
          'ThemeURI' => string 'http://example.com/' (length=22)
          'Description' => string 'Description' (length=11)
          'Author' => string 'Something Here' (length=14)
          'AuthorURI' => string 'http://example.com/' (length=22)
          'Version' => string '1.0.0' (length=5)
          'Template' => string '' (length=0)
          'Status' => string '' (length=0)
          'Tags' => string 'custom-background, custom-logo, custom-menu, featured-images, threaded-comments, translation-ready' (length=98)
          'TextDomain' => string 'mytheme' (length=7)
          'DomainPath' => string '' (length=0)
      private 'headers_sanitized' => null
      private 'name_translated' => null
      private 'errors' => null
      private 'stylesheet' => string 'mytheme' (length=7)
      private 'template' => string 'mytheme' (length=7)
      private 'parent' => null
      private 'theme_root_uri' => null
      private 'textdomain_loaded' => null
      private 'cache_hash' => string 'ca9dd01f01f2a5cb4616a776eff52690' (length=32)

You must log in before being able to contribute a note or feedback.