返回介绍

get_theme_root_uri()

发布于 2017-09-11 00:25:52 字数 3478 浏览 1008 评论 0 收藏 0

get_theme_root_uri( string $stylesheet_or_template = false,  string $theme_root = false )

Retrieve URI for themes directory.


description

Does not have trailing slash.


参数

$stylesheet_or_template

(string) (Optional) The stylesheet or template name of the theme. Default is to leverage the main theme root.

Default value: false

$theme_root

(string) (Optional) The theme root for which calculations will be based, preventing the need for a get_raw_theme_root() call.

Default value: false


返回值

(string) Themes URI.


源代码

File: wp-includes/theme.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 );
}

更新日志

Versiondescription
1.5.0Introduced.

相关函数

Uses

  • wp-includes/theme.php: get_raw_theme_root()
  • wp-includes/theme.php: theme_root_uri
  • wp-includes/link-template.php: content_url()
  • wp-includes/link-template.php: plugins_url()
  • wp-includes/link-template.php: site_url()
  • wp-includes/plugin.php: apply_filters()
  • wp-includes/option.php: get_option()
  • Show 2 more uses Hide more uses

Used By

  • wp-includes/theme.php: get_stylesheet_directory_uri()
  • wp-includes/theme.php: get_template_directory_uri()
  • wp-includes/class-wp-theme.php: WP_Theme::get_theme_root_uri()

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文