Using WordPress ‘get_stylesheet_uri()’ PHP function

The get_stylesheet_uri() WordPress PHP function retrieves the URI for the active theme’s stylesheet.

Usage

To use the function, simply call it like this:

echo get_stylesheet_uri();

This will output the URI of the active theme’s stylesheet, typically named style.css.

Parameters

  • None

More information

See WordPress Developer Resources: get_stylesheet_uri()

This function is available since WordPress version 1.5.0.

Examples

Enqueue the active theme’s stylesheet

Enqueue the active theme’s stylesheet in your theme’s functions.php file to properly load the style.css.

function my_theme_styles() {
    wp_enqueue_style('my-theme-style', get_stylesheet_uri());
}
add_action('wp_enqueue_scripts', 'my_theme_styles');

Display an inline style with the active theme’s stylesheet URL

Create an inline style tag with the active theme’s stylesheet URL in the header.php file.

<style>
@import url('<?php echo get_stylesheet_uri(); ?>');
</style>

Load the active theme’s stylesheet conditionally

Load the active theme’s stylesheet only on specific pages by modifying the functions.php file.

function my_theme_styles() {
    if (is_front_page()) {
        wp_enqueue_style('my-theme-style', get_stylesheet_uri());
    }
}
add_action('wp_enqueue_scripts', 'my_theme_styles');

Add a version number to the active theme’s stylesheet

Add a version number to the active theme’s stylesheet when enqueued in the functions.php file.

function my_theme_styles() {
    wp_enqueue_style('my-theme-style', get_stylesheet_uri(), array(), '1.0.0');
}
add_action('wp_enqueue_scripts', 'my_theme_styles');

Load a Google Font alongside the active theme’s stylesheet

Enqueue a Google Font with the active theme’s stylesheet in the functions.php file.

function my_theme_styles() {
    wp_enqueue_style('google-font', 'https://fonts.googleapis.com/css?family=Roboto', array(), null);
    wp_enqueue_style('my-theme-style', get_stylesheet_uri(), array('google-font'));
}
add_action('wp_enqueue_scripts', 'my_theme_styles');