Title: enqueue_block_styles_assets
Published: November 12, 2019
Last modified: February 24, 2026

---

# enqueue_block_styles_assets()

## In this article

 * [Source](https://developer.wordpress.org/reference/functions/enqueue_block_styles_assets/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/enqueue_block_styles_assets/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/enqueue_block_styles_assets/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/enqueue_block_styles_assets/?output_format=md#user-contributed-notes)

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

Function responsible for enqueuing the styles required for block styles functionality
on the editor and on the frontend.

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

    ```php
    function enqueue_block_styles_assets() {
    	global $wp_styles;

    	$block_styles = WP_Block_Styles_Registry::get_instance()->get_all_registered();

    	foreach ( $block_styles as $block_name => $styles ) {
    		foreach ( $styles as $style_properties ) {
    			if ( isset( $style_properties['style_handle'] ) ) {

    				// If the site loads block styles on demand, enqueue the stylesheet on render.
    				if ( wp_should_load_block_assets_on_demand() ) {
    					add_filter(
    						'render_block',
    						static function ( $html, $block ) use ( $block_name, $style_properties ) {
    							if ( $block['blockName'] === $block_name ) {
    								wp_enqueue_style( $style_properties['style_handle'] );
    							}
    							return $html;
    						},
    						10,
    						2
    					);
    				} else {
    					wp_enqueue_style( $style_properties['style_handle'] );
    				}
    			}
    			if ( isset( $style_properties['inline_style'] ) ) {

    				// Default to "wp-block-library".
    				$handle = 'wp-block-library';

    				// If the site loads block styles on demand, check if the block has a stylesheet registered.
    				if ( wp_should_load_block_assets_on_demand() ) {
    					$block_stylesheet_handle = generate_block_asset_handle( $block_name, 'style' );

    					if ( isset( $wp_styles->registered[ $block_stylesheet_handle ] ) ) {
    						$handle = $block_stylesheet_handle;
    					}
    				}

    				// Add inline styles to the calculated handle.
    				wp_add_inline_style( $handle, $style_properties['inline_style'] );
    			}
    		}
    	}
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/script-loader.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/script-loader.php#L2764)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/script-loader.php#L2764-L2809)

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

| Uses | Description | 
| [wp_should_load_block_assets_on_demand()](https://developer.wordpress.org/reference/functions/wp_should_load_block_assets_on_demand/)`wp-includes/script-loader.php` |

Checks whether block styles should be loaded only on-render.

  | 
| [generate_block_asset_handle()](https://developer.wordpress.org/reference/functions/generate_block_asset_handle/)`wp-includes/blocks.php` |

Generates the name for an asset based on the name of the block and the field name provided.

  | 
| [WP_Block_Styles_Registry::get_instance()](https://developer.wordpress.org/reference/classes/wp_block_styles_registry/get_instance/)`wp-includes/class-wp-block-styles-registry.php` |

Utility method to retrieve the main instance of the class.

  | 
| [wp_enqueue_style()](https://developer.wordpress.org/reference/functions/wp_enqueue_style/)`wp-includes/functions.wp-styles.php` |

Enqueues a CSS stylesheet.

  | 
| [wp_add_inline_style()](https://developer.wordpress.org/reference/functions/wp_add_inline_style/)`wp-includes/functions.wp-styles.php` |

Adds extra CSS styles to a registered stylesheet.

  | 
| [add_filter()](https://developer.wordpress.org/reference/functions/add_filter/)`wp-includes/plugin.php` |

Adds a callback function to a filter hook.

  |

[Show 1 more](https://developer.wordpress.org/reference/functions/enqueue_block_styles_assets/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/enqueue_block_styles_assets/?output_format=md#)

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

| Version | Description | 
| [5.3.0](https://developer.wordpress.org/reference/since/5.3.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/enqueue_block_styles_assets/?output_format=md#user-contributed-notes)󠁿

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/functions/enqueue_block_styles_assets/?output_format=md#comment-content-5780)
 2.   [Will Skora](https://profiles.wordpress.org/skorasaurus/)  [  4 years ago  ](https://developer.wordpress.org/reference/functions/enqueue_block_styles_assets/#comment-5780)
 3. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fenqueue_block_styles_assets%2F%23comment-5780)
    Vote results for this note: 2[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fenqueue_block_styles_assets%2F%23comment-5780)
 4. If you want opt-out of loading CSS for the core blocks, loaded in the wp-block-
    library stylesheet, you can do so by the following:
 5.     ```php
        function mytheme_block_assets() {
        	wp_deregister_style( 'wp-block-library' );
        	wp_register_style( 'wp-block-library', '' );
        }
        add_action( 'enqueue_block_assets', 'mytheme_block_assets' );
        ```
    
 6. (credit to [Adam Jacobi and Brad Thomason ](https://github.com/WordPress/gutenberg/issues/40235#issuecomment-1096969886))
 7.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fenqueue_block_styles_assets%2F%3Freplytocom%3D5780%23feedback-editor-5780)

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