get_theme_root

Retrieve path to themes directory.

Description

(string) get_theme_root( (bool) $stylesheet_or_template = false ); 

Does not have trailing slash.

Returns (string)

Theme path.

Parameters (1)

0. $stylesheet_or_template — Optional. (bool) => false
The stylesheet or template name of the theme

Usage

  1. if ( !function_exists( 'get_theme_root' ) ) { 
  2. require_once ABSPATH . WPINC . '/theme.php'; 
  3.  
  4. // The stylesheet or template name of the theme 
  5. $stylesheet_or_template = false; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = get_theme_root($stylesheet_or_template); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/theme.php  
  1. function get_theme_root( $stylesheet_or_template = false ) { 
  2. global $wp_theme_directories; 
  3.  
  4. if ( $stylesheet_or_template && $theme_root = get_raw_theme_root( $stylesheet_or_template ) ) { 
  5. // Always prepend WP_CONTENT_DIR unless the root currently registered as a theme directory. 
  6. // This gives relative theme roots the benefit of the doubt when things go haywire. 
  7. if ( ! in_array( $theme_root, (array) $wp_theme_directories ) ) 
  8. $theme_root = WP_CONTENT_DIR . $theme_root; 
  9. } else { 
  10. $theme_root = WP_CONTENT_DIR . '/themes'; 
  11.  
  12. /** 
  13. * Filters the absolute path to the themes directory. 
  14. * @since 1.5.0 
  15. * @param string $theme_root Absolute path to themes directory. 
  16. */ 
  17. return apply_filters( 'theme_root', $theme_root );