wp_get_theme
Gets a WP_Theme object for a theme.
Description
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
if ( !function_exists( 'wp_get_theme' ) ) { require_once ABSPATH . WPINC . '/theme.php'; } // Directory name for the theme. Optional. Defaults to current theme. $stylesheet = 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). $theme_root = null; // NOTICE! Understand what this does before running. $result = wp_get_theme($stylesheet, $theme_root);
Defined (1)
The function is defined in the following location(s).
- /wp-includes/theme.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 );
- }