检索主题目录的URI。
原型
get_theme_root_uri( string $stylesheet_or_template = false, string $theme_root = false )
描述
没有尾随斜杠。
参数
$stylesheet_or_template
(string)
(Optional)
主题的样式表或模板名称。默认是利用主题主根。
$theme_root
(string)
(Optional)
计算将基于的主题根,防止需要get_raw_theme_root()调用。
返回值
(string)
主题URI。
源文件
路径:wp-includes/theme.php
<?php
...
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' );
}
/**
* Filters 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 );
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/get_theme_root_uri/