Title: WP_Style_Engine::store_css_rule
Published: November 2, 2022
Last modified: May 20, 2026

---

# WP_Style_Engine::store_css_rule( string $store_name, string $css_selector, string[] $css_declarations, string $rules_group = '' )

## In this article

 * [Parameters](https://developer.wordpress.org/reference/classes/wp_style_engine/store_css_rule/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/classes/wp_style_engine/store_css_rule/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_style_engine/store_css_rule/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_style_engine/store_css_rule/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_style_engine/store_css_rule/?output_format=md#wp--skip-link--target)

Stores a CSS rule using the provided CSS selector and CSS declarations.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wp_style_engine/store_css_rule/?output_format=md#parameters)󠁿

 `$store_name`stringrequired

A valid store key.

`$css_selector`stringrequired

When a selector is passed, the function will return a full CSS rule `$selector {...
rules }` otherwise a concatenated string of properties and values.

`$css_declarations`string[]required

An associative array of CSS definitions, e.g. `array( "$property" => "$value", "
$property" => "$value" )`.

`$rules_group`stringoptional

A parent CSS selector in the case of nested CSS, or a CSS nested @rule, such as `
@media (min-width: 80rem)` or `@layer module`.

Default:`''`

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_style_engine/store_css_rule/?output_format=md#source)󠁿

    ```php
    public static function store_css_rule( $store_name, $css_selector, $css_declarations, $rules_group = '' ) {
    	if ( empty( $store_name ) || empty( $css_selector ) || empty( $css_declarations ) ) {
    		return;
    	}
    	static::get_store( $store_name )->add_rule( $css_selector, $rules_group )->add_declarations( $css_declarations );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/style-engine/class-wp-style-engine.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/style-engine/class-wp-style-engine.php#L419)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/style-engine/class-wp-style-engine.php#L419-L424)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_style_engine/store_css_rule/?output_format=md#related)󠁿

| Used by | Description | 
| [wp_style_engine_get_styles()](https://developer.wordpress.org/reference/functions/wp_style_engine_get_styles/)`wp-includes/style-engine.php` |

Global public interface method to generate styles from a single style object, e.g. the value of a block’s attributes.style object or the top level styles in theme.json.

  | 
| [wp_style_engine_get_stylesheet_from_css_rules()](https://developer.wordpress.org/reference/functions/wp_style_engine_get_stylesheet_from_css_rules/)`wp-includes/style-engine.php` |

Returns compiled CSS from a collection of selectors and declarations.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_style_engine/store_css_rule/?output_format=md#changelog)󠁿

| Version | Description | 
| [6.6.0](https://developer.wordpress.org/reference/since/6.6.0/) | Added the `$rules_group` parameter. | 
| [6.1.0](https://developer.wordpress.org/reference/since/6.1.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_style_engine%2Fstore_css_rule%2F)
before being able to contribute a note or feedback.