wp_get_theme

The timeline below displays how wordpress function wp_get_theme has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

/**
 * Gets a WP_Theme object for a theme.
 *
 * @since 3.4.0
 *
 * @global array $wp_theme_directories
 *
 * @param string $stylesheet Optional. Directory name for the theme. Defaults to active theme.
 * @param string $theme_root 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).
 * @return WP_Theme Theme object. Be sure to check the object's exists() method
 *                  if you need to confirm the theme's existence.
 */
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);
}

WordPress Version: 5.5

/**
 * Gets a WP_Theme object for a theme.
 *
 * @since 3.4.0
 *
 * @global array $wp_theme_directories
 *
 * @param string $stylesheet Optional. Directory name for the theme. Defaults to current theme.
 * @param string $theme_root 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 current theme).
 * @return WP_Theme Theme object. Be sure to check the object's exists() method
 *                  if you need to confirm the theme's existence.
 */
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);
}

WordPress Version: 5.3

/**
 * Gets a WP_Theme object for a theme.
 *
 * @since 3.4.0
 *
 * @global array $wp_theme_directories
 *
 * @param string $stylesheet Directory name for the theme. Optional. Defaults to current theme.
 * @param string $theme_root 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).
 * @return WP_Theme Theme object. Be sure to check the object's exists() method if you need to confirm the theme's existence.
 */
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);
}

WordPress Version: 5.1

/**
 * Gets a WP_Theme object for a theme.
 *
 * @since 3.4.0
 *
 * @global array $wp_theme_directories
 *
 * @param string $stylesheet Directory name for the theme. Optional. Defaults to current theme.
 * @param string $theme_root 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).
 * @return WP_Theme Theme object. Be sure to check the object's exists() method if you need to confirm the theme's existence.
 */
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);
}

WordPress Version: 4.3

/**
 * Gets a WP_Theme object for a theme.
 *
 * @since 3.4.0
 *
 * @global array $wp_theme_directories
 *
 * @param string $stylesheet Directory name for the theme. Optional. Defaults to current theme.
 * @param string $theme_root 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).
 * @return WP_Theme Theme object. Be sure to check the object's exists() method if you need to confirm the theme's existence.
 */
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);
}

WordPress Version: 3.7

/**
 * Gets a WP_Theme object for a theme.
 *
 * @since 3.4.0
 *
 * @param string $stylesheet Directory name for the theme. Optional. Defaults to current theme.
 * @param string $theme_root 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).
 * @return WP_Theme Theme object. Be sure to check the object's exists() method if you need to confirm the theme's existence.
 */
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);
}