get_stylesheet_directory_uri() WordPress Function

The get_stylesheet_directory_uri() function is used to retrieve the URL of the current theme's stylesheet directory. This function is useful for retrieving the URL of files such as CSS and JavaScript files that are located in the theme's stylesheet directory.

get_stylesheet_directory_uri() #

Retrieves stylesheet directory URI for the active theme.


Return

(string) URI to active theme's stylesheet directory.


Top ↑

More Information

  • The returned URI does not contain a trailing slash.
  • This function 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.

Top ↑

Source

File: wp-includes/theme.php

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";

	/**
	 * Filters 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 );
}


Top ↑

Changelog

Changelog
VersionDescription
1.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More