get_theme_root

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

WordPress Version: 6.3

/**
 * Retrieves path to themes directory.
 *
 * Does not have trailing slash.
 *
 * @since 1.5.0
 *
 * @global array $wp_theme_directories
 *
 * @param string $stylesheet_or_template Optional. The stylesheet or template name of the theme.
 *                                       Default is to leverage the main theme root.
 * @return string Themes directory path.
 */
function get_theme_root($stylesheet_or_template = '')
{
    global $wp_theme_directories;
    $theme_root = '';
    if ($stylesheet_or_template) {
        $theme_root = get_raw_theme_root($stylesheet_or_template);
        if ($theme_root) {
            /*
             * Always prepend WP_CONTENT_DIR unless the root currently registered as a theme directory.
             * This gives relative theme roots the benefit of the doubt when things go haywire.
             */
            if (!in_array($theme_root, (array) $wp_theme_directories, true)) {
                $theme_root = WP_CONTENT_DIR . $theme_root;
            }
        }
    }
    if (!$theme_root) {
        $theme_root = WP_CONTENT_DIR . '/themes';
    }
    /**
     * Filters the absolute path to the themes directory.
     *
     * @since 1.5.0
     *
     * @param string $theme_root Absolute path to themes directory.
     */
    return apply_filters('theme_root', $theme_root);
}

WordPress Version: 5.5

/**
 * Retrieves path to themes directory.
 *
 * Does not have trailing slash.
 *
 * @since 1.5.0
 *
 * @global array $wp_theme_directories
 *
 * @param string $stylesheet_or_template Optional. The stylesheet or template name of the theme.
 *                                       Default is to leverage the main theme root.
 * @return string Themes directory path.
 */
function get_theme_root($stylesheet_or_template = '')
{
    global $wp_theme_directories;
    $theme_root = '';
    if ($stylesheet_or_template) {
        $theme_root = get_raw_theme_root($stylesheet_or_template);
        if ($theme_root) {
            // Always prepend WP_CONTENT_DIR unless the root currently registered as a theme directory.
            // This gives relative theme roots the benefit of the doubt when things go haywire.
            if (!in_array($theme_root, (array) $wp_theme_directories, true)) {
                $theme_root = WP_CONTENT_DIR . $theme_root;
            }
        }
    }
    if (!$theme_root) {
        $theme_root = WP_CONTENT_DIR . '/themes';
    }
    /**
     * Filters the absolute path to the themes directory.
     *
     * @since 1.5.0
     *
     * @param string $theme_root Absolute path to themes directory.
     */
    return apply_filters('theme_root', $theme_root);
}

WordPress Version: 5.3

/**
 * Retrieve path to themes directory.
 *
 * Does not have trailing slash.
 *
 * @since 1.5.0
 *
 * @global array $wp_theme_directories
 *
 * @param string $stylesheet_or_template Optional. The stylesheet or template name of the theme.
 *                                       Default is to leverage the main theme root.
 * @return string Themes directory path.
 */
function get_theme_root($stylesheet_or_template = '')
{
    global $wp_theme_directories;
    $theme_root = '';
    if ($stylesheet_or_template) {
        $theme_root = get_raw_theme_root($stylesheet_or_template);
        if ($theme_root) {
            // Always prepend WP_CONTENT_DIR unless the root currently registered as a theme directory.
            // This gives relative theme roots the benefit of the doubt when things go haywire.
            if (!in_array($theme_root, (array) $wp_theme_directories)) {
                $theme_root = WP_CONTENT_DIR . $theme_root;
            }
        }
    }
    if (!$theme_root) {
        $theme_root = WP_CONTENT_DIR . '/themes';
    }
    /**
     * Filters the absolute path to the themes directory.
     *
     * @since 1.5.0
     *
     * @param string $theme_root Absolute path to themes directory.
     */
    return apply_filters('theme_root', $theme_root);
}

WordPress Version: 4.6

/**
 * Retrieve path to themes directory.
 *
 * Does not have trailing slash.
 *
 * @since 1.5.0
 *
 * @global array $wp_theme_directories
 *
 * @param string $stylesheet_or_template The stylesheet or template name of the theme
 * @return string Theme path.
 */
function get_theme_root($stylesheet_or_template = false)
{
    global $wp_theme_directories;
    if ($stylesheet_or_template && $theme_root = get_raw_theme_root($stylesheet_or_template)) {
        // Always prepend WP_CONTENT_DIR unless the root currently registered as a theme directory.
        // This gives relative theme roots the benefit of the doubt when things go haywire.
        if (!in_array($theme_root, (array) $wp_theme_directories)) {
            $theme_root = WP_CONTENT_DIR . $theme_root;
        }
    } else {
        $theme_root = WP_CONTENT_DIR . '/themes';
    }
    /**
     * Filters the absolute path to the themes directory.
     *
     * @since 1.5.0
     *
     * @param string $theme_root Absolute path to themes directory.
     */
    return apply_filters('theme_root', $theme_root);
}

WordPress Version: 4.3

/**
 * Retrieve path to themes directory.
 *
 * Does not have trailing slash.
 *
 * @since 1.5.0
 *
 * @global array $wp_theme_directories
 *
 * @param string $stylesheet_or_template The stylesheet or template name of the theme
 * @return string Theme path.
 */
function get_theme_root($stylesheet_or_template = false)
{
    global $wp_theme_directories;
    if ($stylesheet_or_template && $theme_root = get_raw_theme_root($stylesheet_or_template)) {
        // Always prepend WP_CONTENT_DIR unless the root currently registered as a theme directory.
        // This gives relative theme roots the benefit of the doubt when things go haywire.
        if (!in_array($theme_root, (array) $wp_theme_directories)) {
            $theme_root = WP_CONTENT_DIR . $theme_root;
        }
    } else {
        $theme_root = WP_CONTENT_DIR . '/themes';
    }
    /**
     * Filter the absolute path to the themes directory.
     *
     * @since 1.5.0
     *
     * @param string $theme_root Absolute path to themes directory.
     */
    return apply_filters('theme_root', $theme_root);
}

WordPress Version: 3.8

/**
 * Retrieve path to themes directory.
 *
 * Does not have trailing slash.
 *
 * @since 1.5.0
 *
 * @param string $stylesheet_or_template The stylesheet or template name of the theme
 * @return string Theme path.
 */
function get_theme_root($stylesheet_or_template = false)
{
    global $wp_theme_directories;
    if ($stylesheet_or_template && $theme_root = get_raw_theme_root($stylesheet_or_template)) {
        // Always prepend WP_CONTENT_DIR unless the root currently registered as a theme directory.
        // This gives relative theme roots the benefit of the doubt when things go haywire.
        if (!in_array($theme_root, (array) $wp_theme_directories)) {
            $theme_root = WP_CONTENT_DIR . $theme_root;
        }
    } else {
        $theme_root = WP_CONTENT_DIR . '/themes';
    }
    /**
     * Filter the absolute path to the themes directory.
     *
     * @since 1.5.0
     *
     * @param string $theme_root Absolute path to themes directory.
     */
    return apply_filters('theme_root', $theme_root);
}

WordPress Version: 3.7

/**
 * Retrieve path to themes directory.
 *
 * Does not have trailing slash.
 *
 * @since 1.5.0
 * @uses apply_filters() Calls 'theme_root' filter on path.
 *
 * @param string $stylesheet_or_template The stylesheet or template name of the theme
 * @return string Theme path.
 */
function get_theme_root($stylesheet_or_template = false)
{
    global $wp_theme_directories;
    if ($stylesheet_or_template && $theme_root = get_raw_theme_root($stylesheet_or_template)) {
        // Always prepend WP_CONTENT_DIR unless the root currently registered as a theme directory.
        // This gives relative theme roots the benefit of the doubt when things go haywire.
        if (!in_array($theme_root, (array) $wp_theme_directories)) {
            $theme_root = WP_CONTENT_DIR . $theme_root;
        }
    } else {
        $theme_root = WP_CONTENT_DIR . '/themes';
    }
    return apply_filters('theme_root', $theme_root);
}