get_stylesheet_directory_uri()获取当前主题样式表style.css所在的网址目录

目录

描述

译文

检索样式表单目录URI

原文

Retrieve stylesheet directory URI for the current theme/child theme. Checks for SSL.

Note: Does not contain a trailing slash.

Note that this returns a properly-formed URI; in other words, it will be a web-address (starting with http:// or https:// for SSL). As such, it is most appropriately used for links, referencing additional stylesheets, or probably most commonly, images.

In the event a child theme is being used, this function will return the child's theme directory URI.
Use get_template_directory_uri() to avoid being overridden by a child theme.

If you want to include a local file in PHP, use get_stylesheet_directory() instead.

get_stylesheet_directory_uri() 描述

用法

Use the URI<?php get_stylesheet_directory_uri(); ?>Output the URI<?php echo get_stylesheet_directory_uri(); ?>

get_stylesheet_directory_uri() 用法

参数

返回值

uri (string

Stylesheet directory URI.

get_stylesheet_directory_uri() 返回值

示例

Image (HTML)

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */

<img src="<?php echo get_stylesheet_directory_uri(); ?>/images/aternus.png" alt="" width="" height="" />

get_stylesheet_directory_uri() 示例

注意

get_stylesheet_directory_uri() 注意

历史

  • 添加于 版本: 1.5.0

get_stylesheet_directory_uri() 历史

源文件

get_stylesheet_directory_uri() 函数的代码位于 wp-includes/theme.php.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Retrieve stylesheet directory URI.
 *
 * @since 1.5.0
 *
 * @return string
 */
function get_stylesheet_directory_uri() {
	$stylesheet = str_replace( '%2F', '/', rawurlencode( get_stylesheet() ) );
	$theme_root_uri = get_theme_root_uri( $stylesheet );
	$stylesheet_dir_uri = "$theme_root_uri/$stylesheet";

	/**
	 * Filter the stylesheet directory URI.
	 *
	 * @since 1.5.0
	 *
	 * @param string $stylesheet_dir_uri Stylesheet directory URI.
	 * @param string $stylesheet         Name of the activated theme's directory.
	 * @param string $theme_root_uri     Themes root URI.
	 */
	return apply_filters( 'stylesheet_directory_uri', $stylesheet_dir_uri, $stylesheet, $theme_root_uri );
}

get_stylesheet_directory_uri() 源文件

相关