get_stylesheet_directory_uri()WP 1.5.0

Retrieve stylesheet directory URI.

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.

1 time — 0.000068 sec (very fast) | 50000 times — 1.02 sec (fast) | PHP 7.0.2, WP 4.4.1
Hooks from the function

Return

String. URI to active theme's stylesheet directory.

Usage

get_stylesheet_directory_uri();

Examples

0

#1 Display an image from theme directory:

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

#2 Loading css styles:

add_action( 'wp_enqueue_scripts', 'my_scripts_method' );

function my_scripts_method() {

	$url = get_stylesheet_directory_uri() . '/js/custom_script.js';
	wp_enqueue_script( 'custom_script', $url, [ 'jquery' ], '1.0', true );
}
0

#3 Example

Website URL: https://example.com/
Active theme folder: mytheme-child - this is child theme and the parent theme is mytheme.

This function returns the following string:

https://example.com/wp-content/themes/mytheme-child

NOTE: without trailing slash (/)

Changelog

Since 1.5.0 Introduced.

Code of get_stylesheet_directory_uri() WP 6.0

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 );
}