get_theme_root_uri

函式
get_theme_root_uri ( $stylesheet_or_template = '', $theme_root = '' )
引數
  • (string) $stylesheet_or_template Optional. The stylesheet or template name of the theme. Default is to leverage the main theme root.
    Required:
    Default: (empty)
  • (string) $theme_root Optional. The theme root for which calculations will be based, preventing the need for a get_raw_theme_root() call. Default empty.
    Required:
    Default: (empty)
返回值
  • (string) Themes directory URI.
定義位置
相關方法
get_theme_rootget_theme_rootsget_theme_file_uriget_raw_theme_rootwp_get_theme_error
引入
1.5.0
棄用
-

get_theme_root_uri:該函式返回包含所有已安裝主題的目錄的URI。這個URI用於載入主題檔案,如style.css和JavaScript檔案。

檢索主題目錄的URI。

不含尾部斜線。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function get_theme_root_uri( $stylesheet_or_template = '', $theme_root = '' ) {
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, true ) ) {
// 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 The stylesheet or template name of the theme.
*/
return apply_filters( 'theme_root_uri', $theme_root_uri, get_option( 'siteurl' ), $stylesheet_or_template );
}
function get_theme_root_uri( $stylesheet_or_template = '', $theme_root = '' ) { 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, true ) ) { // 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 The stylesheet or template name of the theme. */ return apply_filters( 'theme_root_uri', $theme_root_uri, get_option( 'siteurl' ), $stylesheet_or_template ); }
function get_theme_root_uri( $stylesheet_or_template = '', $theme_root = '' ) {
	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, true ) ) {
			// 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 The stylesheet or template name of the theme.
	 */
	return apply_filters( 'theme_root_uri', $theme_root_uri, get_option( 'siteurl' ), $stylesheet_or_template );
}

常見問題

FAQs
檢視更多 >