get_theme_roots() WordPress Function

The get_theme_roots() function is used to retrieve the absolute path to the directory of a theme. This function is useful for retrieving the path of a theme when you need to use it in a script.

get_theme_roots() #

Retrieves theme roots.


Return

(array|string) An array of theme roots keyed by template/stylesheet or a single theme root if all themes have the same root.


Top ↑

More Information

The names of theme directories are without the trailing but with the leading slash.


Top ↑

Source

File: wp-includes/theme.php

function get_theme_roots() {
	global $wp_theme_directories;

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

	$theme_roots = get_site_transient( 'theme_roots' );
	if ( false === $theme_roots ) {
		search_theme_directories( true ); // Regenerate the transient.
		$theme_roots = get_site_transient( 'theme_roots' );
	}
	return $theme_roots;
}


Top ↑

Changelog

Changelog
VersionDescription
2.9.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