wp_get_theme

Gets a WP_Theme object for a theme.

Description

(WP_Theme) wp_get_theme( (constant) $stylesheet = null, (null) $theme_root = null ); 

Returns (WP_Theme)

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

Parameters (2)

0. $stylesheet — Optional. (constant) => null
Directory name for the theme. Optional. Defaults to current theme.
1. $theme_root — Optional. (null) => null
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).

Usage

  1. if ( !function_exists( 'wp_get_theme' ) ) { 
  2. require_once ABSPATH . WPINC . '/theme.php'; 
  3.  
  4. // Directory name for the theme. Optional. Defaults to current theme. 
  5. $stylesheet = null; 
  6.  
  7. // Absolute path of the theme root to look in. Optional. If not specified, get_raw_theme_root() 
  8. // is used to calculate the theme root for the $stylesheet provided (or current theme). 
  9. $theme_root = null; 
  10.  
  11. // NOTICE! Understand what this does before running. 
  12. $result = wp_get_theme($stylesheet, $theme_root); 
  13.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/theme.php  
  1. function wp_get_theme( $stylesheet = null, $theme_root = null ) { 
  2. global $wp_theme_directories; 
  3.  
  4. if ( empty( $stylesheet ) ) 
  5. $stylesheet = get_stylesheet(); 
  6.  
  7. if ( empty( $theme_root ) ) { 
  8. $theme_root = get_raw_theme_root( $stylesheet ); 
  9. if ( false === $theme_root ) 
  10. $theme_root = WP_CONTENT_DIR . '/themes'; 
  11. elseif ( ! in_array( $theme_root, (array) $wp_theme_directories ) ) 
  12. $theme_root = WP_CONTENT_DIR . $theme_root; 
  13.  
  14. return new WP_Theme( $stylesheet, $theme_root );