Retrieves stylesheet directory URI for the active theme.
Source
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 );
}
Hooks
- apply_filters( ‘stylesheet_directory_uri’,
string $stylesheet_dir_uri ,string $stylesheet ,string $theme_root_uri ) Filters the stylesheet directory URI.
Changelog
Version | Description |
---|---|
1.5.0 | Introduced. |
This function returns the URL to the current child theme if a child theme is used. If you want to return the URL to the root/mother theme, use get_template_directory_uri() instead.
Image (HTML)
Given –
Website URL:
https://example.com/
Active theme folder:
mytheme
This function returns the following string:
https://example.com/wp-content/themes/mytheme
NOTE: without trailing slash (/)
When using inside HTML `src` attribute, you should escape the returned URL when you add some files after the function: