get_theme_root_uri( string $stylesheet_or_template = '', string $theme_root = '' )
检索主题目录的URI。
Retrieve URI for themes directory.
说明(Description)
没有尾随斜杠。
参数(Parameters)
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
$stylesheet_or_template | (string) | 可选 | 主题的样式表或模板名称。默认情况是利用主主题根。 |
$theme_root | (string) | 可选 | 将基于其计算的主题根,从而避免需要get_raw_theme_root()调用。 |
返回(Return)
(string)主题目录URI。源码(Source)
/**
* Retrieve URI for themes directory.
*
* Does not have trailing slash.
*
* @since 1.5.0
*
* @global array $wp_theme_directories
*
* @param string $stylesheet_or_template Optional. The stylesheet or template name of the theme.
* Default is to leverage the main theme root.
* @param string $theme_root Optional. The theme root for which calculations will be based, preventing
* the need for a get_raw_theme_root() call.
* @return string Themes URI.
*/
function get_theme_root_uri( $stylesheet_or_template = false, $theme_root = false ) {
global $wp_theme_directories;
if ( $stylesheet_or_template && ! $theme_root )
$theme_root = get_raw_theme_root( $stylesheet_or_template );
if ( $stylesheet_or_template && $theme_root ) {
if ( in_array( $theme_root, (array) $wp_theme_directories ) ) {
// Absolute path. Make an educated guess. YMMV -- but note the filter below.
if ( 0 === strpos( $theme_root, WP_CONTENT_DIR ) )
$theme_root_uri = content_url( str_replace( WP_CONTENT_DIR, '', $theme_root ) );
elseif ( 0 === strpos( $theme_root, ABSPATH ) )
$theme_root_uri = site_url( str_replace( ABSPATH, '', $theme_root ) );
elseif ( 0 === strpos( $theme_root, WP_PLUGIN_DIR ) || 0 === strpos( $theme_root, WPMU_PLUGIN_DIR ) )
$theme_root_uri = plugins_url( basename( $theme_root ), $theme_root );
else
$theme_root_uri = $theme_root;
} else {
$theme_root_uri = content_url( $theme_root );
}
} else {
$theme_root_uri = content_url( 'themes' );
}
/**
* Filter the URI for themes directory.
*
* @since 1.5.0
*
* @param string $theme_root_uri The URI for themes directory.
* @param string $siteurl WordPress web address which is set in General Options.
* @param string $stylesheet_or_template Stylesheet or template name of the theme.
*/
return apply_filters( 'theme_root_uri', $theme_root_uri, get_option( 'siteurl' ), $stylesheet_or_template );
}
更新版本 | 源码位置 | 使用 | 被使用 |
---|---|---|---|
1.5.0 | wp-includes/theme.php:621 | 3 | 7 |