Using WordPress ‘locale_stylesheet_uri’ PHP filter

The locale_stylesheet_uri WordPress PHP Filter allows you to modify the localized stylesheet URI.

Usage

add_filter( 'locale_stylesheet_uri', 'your_custom_function', 10, 2 );
function your_custom_function( $stylesheet_uri, $stylesheet_dir_uri ) {
    // your custom code here
    return $stylesheet_uri;
}

Parameters

  • $stylesheet_uri (string) – The localized stylesheet URI.
  • $stylesheet_dir_uri (string) – The stylesheet directory URI.

More information

See WordPress Developer Resources: locale_stylesheet_uri

Examples

Change the localized stylesheet URI

Modify the localized stylesheet URI to use a custom path:

add_filter( 'locale_stylesheet_uri', 'change_localized_stylesheet', 10, 2 );
function change_localized_stylesheet( $stylesheet_uri, $stylesheet_dir_uri ) {
    return $stylesheet_dir_uri . '/custom-localized-stylesheet.css';
}

Add version to the localized stylesheet URI

Append the theme version to the stylesheet URI as a query parameter:

add_filter( 'locale_stylesheet_uri', 'add_stylesheet_version', 10, 2 );
function add_stylesheet_version( $stylesheet_uri, $stylesheet_dir_uri ) {
    $theme = wp_get_theme();
    return $stylesheet_uri . '?ver=' . $theme->get( 'Version' );
}

Load a different stylesheet for specific language

Load a different stylesheet based on the site language:

add_filter( 'locale_stylesheet_uri', 'load_language_specific_stylesheet', 10, 2 );
function load_language_specific_stylesheet( $stylesheet_uri, $stylesheet_dir_uri ) {
    $language = get_locale();
    if ( 'fr_FR' === $language ) {
        return $stylesheet_dir_uri . '/french-stylesheet.css';
    }
    return $stylesheet_uri;
}

Serve stylesheet from CDN

Serve the localized stylesheet from a Content Delivery Network (CDN):

add_filter( 'locale_stylesheet_uri', 'serve_stylesheet_from_cdn', 10, 2 );
function serve_stylesheet_from_cdn( $stylesheet_uri, $stylesheet_dir_uri ) {
    return 'https://cdn.example.com/your-theme/localized-stylesheet.css';
}

Disable the localized stylesheet

Prevent the localized stylesheet from being loaded:

add_filter( 'locale_stylesheet_uri', '__return_false' );