On this page
get_theme_root( string $stylesheet_or_template = '' ): string
Retrieves path to themes directory.
Description
Does not have trailing slash.
Parameters
$stylesheet_or_templatestring Optional-
The stylesheet or template name of the theme.
Default is to leverage the main theme root.Default:
''
Return
string Themes directory path.
Source
File: wp-includes/theme.php. View all references
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 );
}
Hooks
- apply_filters( 'theme_root',
string $theme_root ) -
Filters the absolute path to the themes directory.
Related
Uses
| Uses | Description |
|---|---|
| get_raw_theme_root() wp-includes/theme.php | Gets the raw theme root relative to the content directory with no filters applied. |
| apply_filters() wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. |
Used By
| Used By | Description |
|---|---|
| get_block_theme_folders() wp-includes/block-template-utils.php | For backward compatibility reasons, block themes might be using block-templates or block-template-parts, this function ensures we fallback to these folders properly. |
| WP_Debug_Data::get_sizes() wp-admin/includes/class-wp-debug-data.php | Fetches the sizes of the WordPress directories: |
| WP_Debug_Data::debug_data() wp-admin/includes/class-wp-debug-data.php | Static function for generating site debug data when required. |
| WP_Automatic_Updater::update() wp-admin/includes/class-wp-automatic-updater.php | Updates an item, if appropriate. |
| Theme_Upgrader::check_parent_theme_filter() wp-admin/includes/class-theme-upgrader.php | Check if a child theme is being installed and we need to install its parent. |
| Theme_Upgrader::install() wp-admin/includes/class-theme-upgrader.php | Install a theme package. |
| Theme_Upgrader::upgrade() wp-admin/includes/class-theme-upgrader.php | Upgrade a theme. |
| Theme_Upgrader::bulk_upgrade() wp-admin/includes/class-theme-upgrader.php | Upgrade several themes at once. |
| WP_Upgrader::fs_connect() wp-admin/includes/class-wp-upgrader.php | Connect to the filesystem. |
| WP_Filesystem_Base::wp_themes_dir() wp-admin/includes/class-wp-filesystem-base.php | Returns the path on the remote filesystem of the Themes Directory. |
| get_stylesheet_directory() wp-includes/theme.php | Retrieves stylesheet directory path for the active theme. |
| get_template_directory() wp-includes/theme.php | Retrieves template directory path for the active theme. |
Changelog
| Version | Description |
|---|---|
| 1.5.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_theme_root