get_theme_root()
Retrieve path to themes directory.
Does not have trailing slash.
1 time — 0.00001 sec (speed of light) | 50000 times — 0.01 sec (speed of light) | PHP 7.4.8, WP 5.6.2
Hooks from the function
Return
String
. Themes directory path.
Usage
get_theme_root( $stylesheet_or_template );
- $stylesheet_or_template(string)
- The stylesheet or template name of the theme.
Default: to leverage the main theme root
Examples
#1 Get the full path to the themes directory:
echo get_theme_root(); //> /home/k/foo/example.com/www/wp-content/themes echo get_theme_root( 'my-theme' ); //> /home/k/foo/example.com/www/wp-content/themes
#2 Number of subdirectories in the themes directory
function display_themes_subdirs_count_info(){ $theme_root = get_theme_root(); $files_array = glob( "$theme_root/*", GLOB_ONLYDIR ); echo count( $files_array ) . " subdirectories in the directory: $theme_root"; }
Notes
- Global. Array. $wp_theme_directories
Changelog
Since 1.5.0 | Introduced. |