register_block_style_handle( array $metadata, string $field_name )

Finds a style handle for the block metadata field. It detects when a path to file was provided and registers the style under automatically generated handle name. It returns unprocessed style handle otherwise.

Parameters Parameters


(array) (Required) Block metadata.


(string) (Required) Field name to pick from metadata.

Top ↑

Return Return

(string|boolean) Style handle provided directly or created through style's registration, or false on failure.

Top ↑

Source Source

File: wp-includes/blocks.php

function register_block_style_handle( $metadata, $field_name ) {
	if ( empty( $metadata[ $field_name ] ) ) {
		return false;
	$style_handle = $metadata[ $field_name ];
	$style_path   = remove_block_asset_path_prefix( $metadata[ $field_name ] );
	if ( $style_handle === $style_path ) {
		return $style_handle;

	$style_handle = generate_block_asset_handle( $metadata['name'], $field_name );
	$block_dir    = dirname( $metadata['file'] );
	$result       = wp_register_style(
		plugins_url( $style_path, $metadata['file'] ),
		filemtime( realpath( "$block_dir/$style_path" ) )
	return $result ? $style_handle : false;

Top ↑

Changelog Changelog

Version Description
5.5.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.