WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/get theme root

Description

Retrieves the absolute path to the themes directory, without the trailing slash.

Usage

<?php get_theme_root$stylesheet_or_template ); ?>

Parameters

$stylesheet_or_template
(string) (Optional) The stylesheet or template name of the theme.
Default: false

Return Values

(string) 
Absolute path to the themes directory (without the trailing slash).

Examples

Number of Subdirectories in Themes Directory

The function below informs about the number of subdirectories in the themes directory. Note that this doesn't necessarily match the number of themes recognized by WordPress.

<?php
function display_themes_subdirs_count_info()
  $theme_root = get_theme_root();
  $files_array = glob("$theme_root/*", GLOB_ONLYDIR);
  echo "There are " . count($files_array) . " subdirectories in the " . $theme_root . " directory"; 
}
?>

Example output:

There are 5 subdirectories in the /home/user/public_html/wp-content/themes directory.

Notes

Change Log

Since: 1.5.0

Source File

get_theme_root() is located in wp-includes/theme.php.

Related

Theme paths: get_template(), get_template_directory(), get_template_directory_uri(), get_theme_roots(), get_theme_root(), get_theme_root_uri(), get_stylesheet(), get_stylesheet_uri(), get_stylesheet_directory(), get_stylesheet_directory_uri(), get_bloginfo(), get_theme_file_uri(), get_theme_file_path()

See also index of Function Reference and index of Template Tags.