generate_block_asset_handle() WordPress Function
The generate_block_asset_handle() function is used to generate a unique handle for a given asset. This is useful for caching purposes, as well as for ensuring that assets are only included once in a given page.
generate_block_asset_handle( string $block_name, string $field_name ) #
Generates the name for an asset based on the name of the block and the field name provided.
Parameters
- $block_name
(string)(Required)Name of the block.
- $field_name
(string)(Required)Name of the metadata field.
Return
(string) Generated asset name for the block's field.
Source
File: wp-includes/blocks.php
function generate_block_asset_handle( $block_name, $field_name ) { if ( 0 === strpos( $block_name, 'core/' ) ) { $asset_handle = str_replace( 'core/', 'wp-block-', $block_name ); if ( 0 === strpos( $field_name, 'editor' ) ) { $asset_handle .= '-editor'; } if ( 0 === strpos( $field_name, 'view' ) ) { $asset_handle .= '-view'; } return $asset_handle; } $field_mappings = array( 'editorScript' => 'editor-script', 'script' => 'script', 'viewScript' => 'view-script', 'editorStyle' => 'editor-style', 'style' => 'style', ); return str_replace( '/', '-', $block_name ) . '-' . $field_mappings[ $field_name ]; }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
5.5.0 | Introduced. |