get_theme_root_uri

Retrieve URI for themes directory.

Description

(string) get_theme_root_uri( (constant) $stylesheet_or_template = false, (bool) $theme_root = false ); 

Does not have trailing slash.

Returns (string)

Themes URI.

Parameters (2)

0. $stylesheet_or_template — Optional. (constant) => false
The stylesheet or template name of the theme. Default is to leverage the main theme root.
1. $theme_root — Optional. (bool) => false
The theme root for which calculations will be based, preventing the need for a get_raw_theme_root() call.

Usage

  1. if ( !function_exists( 'get_theme_root_uri' ) ) { 
  2. require_once ABSPATH . WPINC . '/theme.php'; 
  3.  
  4. // Optional. The stylesheet or template name of the theme. 
  5. // Default is to leverage the main theme root. 
  6. $stylesheet_or_template = false; 
  7.  
  8. // Optional. The theme root for which calculations will be based, preventing 
  9. // the need for a get_raw_theme_root() call. 
  10. $theme_root = false; 
  11.  
  12. // NOTICE! Understand what this does before running. 
  13. $result = get_theme_root_uri($stylesheet_or_template, $theme_root); 
  14.  

Defined (1)

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

/wp-includes/theme.php  
  1. function get_theme_root_uri( $stylesheet_or_template = false, $theme_root = false ) { 
  2. global $wp_theme_directories; 
  3.  
  4. if ( $stylesheet_or_template && ! $theme_root ) 
  5. $theme_root = get_raw_theme_root( $stylesheet_or_template ); 
  6.  
  7. if ( $stylesheet_or_template && $theme_root ) { 
  8. if ( in_array( $theme_root, (array) $wp_theme_directories ) ) { 
  9. // Absolute path. Make an educated guess. YMMV -- but note the filter below. 
  10. if ( 0 === strpos( $theme_root, WP_CONTENT_DIR ) ) 
  11. $theme_root_uri = content_url( str_replace( WP_CONTENT_DIR, '', $theme_root ) ); 
  12. elseif ( 0 === strpos( $theme_root, ABSPATH ) ) 
  13. $theme_root_uri = site_url( str_replace( ABSPATH, '', $theme_root ) ); 
  14. elseif ( 0 === strpos( $theme_root, WP_PLUGIN_DIR ) || 0 === strpos( $theme_root, WPMU_PLUGIN_DIR ) ) 
  15. $theme_root_uri = plugins_url( basename( $theme_root ), $theme_root ); 
  16. else 
  17. $theme_root_uri = $theme_root; 
  18. } else { 
  19. $theme_root_uri = content_url( $theme_root ); 
  20. } else { 
  21. $theme_root_uri = content_url( 'themes' ); 
  22.  
  23. /** 
  24. * Filters the URI for themes directory. 
  25. * @since 1.5.0 
  26. * @param string $theme_root_uri The URI for themes directory. 
  27. * @param string $siteurl WordPress web address which is set in General Options. 
  28. * @param string $stylesheet_or_template Stylesheet or template name of the theme. 
  29. */ 
  30. return apply_filters( 'theme_root_uri', $theme_root_uri, get_option( 'siteurl' ), $stylesheet_or_template );