The enqueue_editor_block_styles_assets() WordPress PHP function is used to enqueue the assets needed for block styles functionality in the editor.
On this pageJump to a section
Usage
The function doesn’t require any parameters, so it can be used simply by calling it:
enqueue_editor_block_styles_assets();
Parameters
- The function doesn’t accept any parameters.
More information
See WordPress Developer Resources: enqueue_editor_block_styles_assets()
As of the latest update, there’s no information on this function being deprecated.
Examples
Enqueueing block styles assets in a function
In this example, we have a function named my_custom_function(), where we enqueue the block styles assets:
function my_custom_function() {
enqueue_editor_block_styles_assets();
}
This function, when called, will enqueue the necessary assets for block styles functionality in the editor.
Enqueueing assets on a hook
We use the function inside the admin_enqueue_scripts hook:
add_action('admin_enqueue_scripts', 'enqueue_editor_block_styles_assets');
This will enqueue the block styles assets when admin scripts are being enqueued.
Conditional Enqueueing
We only enqueue the assets if we’re in the post editor:
function conditionally_enqueue() {
global $pagenow;
if ( 'post.php' == $pagenow ) {
enqueue_editor_block_styles_assets();
}
}
add_action( 'admin_init', 'conditionally_enqueue' );
In this example, the assets will be enqueued only when we’re editing a post.
Enqueueing in a custom editor page
In a custom editor page, we enqueue the assets:
function custom_editor_page() {
// Some code here...
enqueue_editor_block_styles_assets();
// More code here...
}
In this scenario, the assets will be enqueued when the custom editor page is rendered.
Enqueueing within a Plugin
If you’re developing a plugin that requires block styles in its settings page, enqueue the assets there:
function my_plugin_settings_page() {
enqueue_editor_block_styles_assets();
// The rest of your settings page code...
}
In this example, the block styles assets will be enqueued when the settings page of your plugin is displayed.