get_raw_theme_root() WordPress Function

The get_raw_theme_root() function is used to get the absolute path to the directory of a given theme. This is useful if you need to access theme files directly, without going through the theme wrapper.

get_raw_theme_root( string $stylesheet_or_template, bool $skip_cache = false ) #

Gets the raw theme root relative to the content directory with no filters applied.


Parameters

$stylesheet_or_template

(string)(Required)The stylesheet or template name of the theme.

$skip_cache

(bool)(Optional) Whether to skip the cache. Defaults to false, meaning the cache is used.

Default value: false


Top ↑

Return

(string) Theme root.


Top ↑

Source

File: wp-includes/theme.php

function get_raw_theme_root( $stylesheet_or_template, $skip_cache = false ) {
	global $wp_theme_directories;

	if ( ! is_array( $wp_theme_directories ) || count( $wp_theme_directories ) <= 1 ) {
		return '/themes';
	}

	$theme_root = false;

	// If requesting the root for the active theme, consult options to avoid calling get_theme_roots().
	if ( ! $skip_cache ) {
		if ( get_option( 'stylesheet' ) == $stylesheet_or_template ) {
			$theme_root = get_option( 'stylesheet_root' );
		} elseif ( get_option( 'template' ) == $stylesheet_or_template ) {
			$theme_root = get_option( 'template_root' );
		}
	}

	if ( empty( $theme_root ) ) {
		$theme_roots = get_theme_roots();
		if ( ! empty( $theme_roots[ $stylesheet_or_template ] ) ) {
			$theme_root = $theme_roots[ $stylesheet_or_template ];
		}
	}

	return $theme_root;
}


Top ↑

Changelog

Changelog
VersionDescription
3.1.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More