Title: get_theme_roots
Published: April 25, 2014
Last modified: February 24, 2026

---

# get_theme_roots(): array|string

## In this article

 * [Return](https://developer.wordpress.org/reference/functions/get_theme_roots/?output_format=md#return)
 * [More Information](https://developer.wordpress.org/reference/functions/get_theme_roots/?output_format=md#more-information)
 * [Source](https://developer.wordpress.org/reference/functions/get_theme_roots/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/get_theme_roots/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/get_theme_roots/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/get_theme_roots/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/get_theme_roots/?output_format=md#wp--skip-link--target)

Retrieves theme roots.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/get_theme_roots/?output_format=md#return)󠁿

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

## 󠀁[More Information](https://developer.wordpress.org/reference/functions/get_theme_roots/?output_format=md#more-information)󠁿

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

## 󠀁[Source](https://developer.wordpress.org/reference/functions/get_theme_roots/?output_format=md#source)󠁿

    ```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;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/theme.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/theme.php#L388)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/theme.php#L388-L401)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/get_theme_roots/?output_format=md#related)󠁿

| Uses | Description | 
| [search_theme_directories()](https://developer.wordpress.org/reference/functions/search_theme_directories/)`wp-includes/theme.php` |

Searches all registered theme directories for complete and valid themes.

  | 
| [get_site_transient()](https://developer.wordpress.org/reference/functions/get_site_transient/)`wp-includes/option.php` |

Retrieves the value of a site transient.

  |

| Used by | Description | 
| [WP_Block_Metadata_Registry::get_default_collection_roots()](https://developer.wordpress.org/reference/classes/wp_block_metadata_registry/get_default_collection_roots/)`wp-includes/class-wp-block-metadata-registry.php` |

Gets the default collection root directory paths.

  | 
| [get_raw_theme_root()](https://developer.wordpress.org/reference/functions/get_raw_theme_root/)`wp-includes/theme.php` |

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

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/get_theme_roots/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.9.0](https://developer.wordpress.org/reference/since/2.9.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/get_theme_roots/?output_format=md#user-contributed-notes)󠁿

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/functions/get_theme_roots/?output_format=md#comment-content-1341)
 2.   [Codex](https://profiles.wordpress.org/codex/)  [  10 years ago  ](https://developer.wordpress.org/reference/functions/get_theme_roots/#comment-1341)
 3. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_theme_roots%2F%23comment-1341)
    Vote results for this note: -1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_theme_roots%2F%23comment-1341)
 4. **Basic Example**
 5.     ```php
        echo get_theme_roots();
        ```
    
 6. If your themes directory is located at /home/www/wp-content/themes/, the above 
    echo statement will output “/themes”.
 7.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_theme_roots%2F%3Freplytocom%3D1341%23feedback-editor-1341)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_theme_roots%2F)
before being able to contribute a note or feedback.