get_stylesheet_uri()
Retrieves the URI of the current theme stylesheet file (style.css).
The stylesheet file name is always style.css
, that's why this function use get_stylesheet_directory_uri() and append the name to the end: http://domain/path/style.css.
If a child theme is used, this function returns the URL to the child theme, not to a parent one.
1 time — 0.000039 sec (very fast) | 50000 times — 0.78 sec (very fast) | PHP 7.0.2, WP 4.4.2
Hooks from the function
Return
String
. URL of the stylesheet file style.css of the current theme.
Usage
get_stylesheet_uri();
Examples
#1 Retrieves the URI of current theme stylesheet
echo get_stylesheet_uri(); // output: http://example.com/wp-content/themes/wp-kama/style.css
#2 Load the current theme stylesheet
If you want to load a stylesheet (CSS) file, you should use wp_enqueue_style() function:
add_action( 'wp_enqueue_scripts', 'enqueue_mytheme_style' ); function enqueue_mytheme_style() { wp_enqueue_style( 'theme-style', get_stylesheet_uri() ); }
Reed more: Better way to include child theme styles (along with parent theme styles).
Changelog
Since 1.5.0 | Introduced. |
get_stylesheet_uri() get stylesheet uri code WP 6.1.1
function get_stylesheet_uri() { $stylesheet_dir_uri = get_stylesheet_directory_uri(); $stylesheet_uri = $stylesheet_dir_uri . '/style.css'; /** * Filters the URI of the active theme stylesheet. * * @since 1.5.0 * * @param string $stylesheet_uri Stylesheet URI for the active theme/child theme. * @param string $stylesheet_dir_uri Stylesheet directory URI for the active theme/child theme. */ return apply_filters( 'stylesheet_uri', $stylesheet_uri, $stylesheet_dir_uri ); }