get_stylesheet_directory_uri(): string
In this article
Retrieves stylesheet directory URI for the active theme.
Return
string URI to active theme’s stylesheet directory.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.
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.
Related
Uses | Description |
---|---|
get_theme_root_uri() wp-includes/theme.php | Retrieves URI for themes directory. |
get_stylesheet() wp-includes/theme.php | Retrieves name of the current stylesheet. |
apply_filters() wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. |
Used by | Description |
---|---|
WP_URL_Pattern_Prefixer::get_default_contexts() wp-includes/class-wp-url-pattern-prefixer.php | Returns the default contexts used by the class. |
WP_REST_Themes_Controller::prepare_item_for_response() wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php | Prepares a single theme output for response. |
get_theme_file_uri() wp-includes/link-template.php | Retrieves the URL of a file in the theme. |
get_editor_stylesheets() wp-includes/theme.php | Retrieves any registered editor stylesheet URLs. |
Custom_Image_Header::get_default_header_images() wp-admin/includes/class-custom-image-header.php | Gets the details of default header images if defined. |
Custom_Image_Header::step_1() wp-admin/includes/class-custom-image-header.php | Displays first step of custom header image page. |
Custom_Image_Header::reset_header_image() wp-admin/includes/class-custom-image-header.php | Resets a header image to the default image for the theme. |
Custom_Image_Header::process_default_headers() wp-admin/includes/class-custom-image-header.php | Processes the default headers. |
WP_Customize_Manager::register_controls() wp-includes/class-wp-customize-manager.php | Registers some default controls. |
_get_random_header_data() wp-includes/theme.php | Gets random header image data from registered images in theme. |
get_custom_header() wp-includes/theme.php | Gets the header image data. |
get_theme_mod() wp-includes/theme.php | Retrieves theme modification value for the active theme. |
get_stylesheet_uri() wp-includes/theme.php | Retrieves stylesheet URI for the active theme. |
get_locale_stylesheet_uri() wp-includes/theme.php | Retrieves the localized stylesheet URI. |
get_bloginfo() wp-includes/general-template.php | Retrieves information about the current site. |
Changelog
Version | Description |
---|---|
1.5.0 | Introduced. |
User Contributed Notes
-
Skip to note 5 content You must log in to vote on the helpfulness of this note Vote results for this note: 16You must log in to vote on the helpfulness of this note -
Skip to note 6 content You must log in to vote on the helpfulness of this note Vote results for this note: 5You must log in to vote on the helpfulness of this noteImage (HTML)
<img src="<?php echo get_stylesheet_directory_uri(); ?>/images/aternus.png" alt="" width="" height="" />
-
Skip to note 7 content You must log in to vote on the helpfulness of this note Vote results for this note: 2You must log in to vote on the helpfulness of this noteGiven –
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 (/)
-
Skip to note 8 content You must log in to vote on the helpfulness of this note Vote results for this note: 0You must log in to vote on the helpfulness of this noteWhen using inside HTML `src` attribute, you should escape the returned URL when you add some files after the function:
<script async type="text/javascript" src="<?php echo esc_url( get_stylesheet_directory_uri() . '/dist/main.js' ); ?>"> </script>
You must log in before being able to contribute a note or feedback.
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.