wp_get_global_styles() WordPress Function
The wp_get_global_styles() function is used to retrieve all the global styles used by a WordPress site. This function is used to get the global styles for a WordPress site. The global styles are the styles that are applied to all the pages on the site. These styles are usually defined in the theme's style.css file.
wp_get_global_styles( array $path = array(), array $context = array() ) #
Function to get the styles resulting of merging core, theme, and user data.
Parameters
- $path
(array)(Optional)Path to the specific style to retrieve. Optional. If empty, will return all styles.
Default value: array()
- $context
(array)(Optional)Metadata to know where to retrieve the $path from. Optional.
- 'block_name'
(string) Which block to retrieve the styles from. If empty, it'll return the styles for the global context. - 'origin'
(string) Which origin to take data from. Valid values are 'all' (core, theme, and user) or 'base' (core and theme). If empty or unknown, 'all' is used.
Default value: array()
- 'block_name'
Return
(array) The styles to retrieve.
Source
File: wp-includes/global-styles-and-settings.php
function wp_get_global_styles( $path = array(), $context = array() ) {
if ( ! empty( $context['block_name'] ) ) {
$path = array_merge( array( 'blocks', $context['block_name'] ), $path );
}
$origin = 'custom';
if ( isset( $context['origin'] ) && 'base' === $context['origin'] ) {
$origin = 'theme';
}
$styles = WP_Theme_JSON_Resolver::get_merged_data( $origin )->get_raw_data()['styles'];
return _wp_array_get( $styles, $path, $styles );
}
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
| Version | Description |
|---|---|
| 5.9.0 | Introduced. |