get_stylesheet_directory(): string
Retrieves stylesheet directory path for the active theme.
Contents
Return
string Path to active theme's stylesheet directory.
More Information
- The returning path does not contain a trailing slash.
- An example output of get_stylesheet_directory() is
/home/user/public_html/wp-content/themes/my_theme - In the event a child theme is being used, that is the directory that will be returned, not the parent theme directory (use get_template_directory() instead if you want the parent directory).
- To retrieve the URI of the stylesheet directory use get_stylesheet_directory_uri()
- To retrieve the path of a parent theme, use get_template_directory()
Source
File: wp-includes/theme.php
.
View all references
function get_stylesheet_directory() {
$stylesheet = get_stylesheet();
$theme_root = get_theme_root( $stylesheet );
$stylesheet_dir = "$theme_root/$stylesheet";
/**
* Filters the stylesheet directory path for the active theme.
*
* @since 1.5.0
*
* @param string $stylesheet_dir Absolute path to the active theme.
* @param string $stylesheet Directory name of the active theme.
* @param string $theme_root Absolute path to themes directory.
*/
return apply_filters( 'stylesheet_directory', $stylesheet_dir, $stylesheet, $theme_root );
}
Hooks
-
apply_filters( 'stylesheet_directory',
string $stylesheet_dir ,string $stylesheet ,string $theme_root ) -
Filters the stylesheet directory path for the active theme.
Changelog
Version | Description |
---|---|
1.5.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.
Basic Example
Include a PHP file
You can also use the constant “STYLESHEETPATH” in replacement of get_stylesheet_directory()
Top ↑
Feedback
IMO it is preferable to use the function rather than the constant, because it includes additional logic that the constant cannot, most prominently the filter, which can allow you to conditionally change the theme on demand. — By crstauf —
get_stylesheet_directory()
retrieves the child-theme’s directory.If you want to retrieve the parent-theme’s directory use
get_template_directory()
instead or even betterloacate_template()
– This way Wordpress automatically uses your child themes directory to look for your resource – if there is a child-theme-file present it will use this one instead. No need for enqueuing anything.