Action Hook since 5.0.0

enqueue_block_editor_assets

Loads scripts/styles inside the block editor only

Description

enqueue_block_editor_assets is the block-editor-only counterpart to wp_enqueue_scripts — it never runs on the public front-end.

When it runs

wp-admin post editor and site editor screens only, when the block editor initializes. Does not run on the public front-end.

Signature

do_action( 'enqueue_block_editor_assets' );

Examples

Basic

add_action( 'enqueue_block_editor_assets', function() {
    wp_enqueue_script(
        'my-block-editor-script',
        get_template_directory_uri() . '/js/editor.js',
        [ 'wp-blocks', 'wp-element', 'wp-editor' ],
        '1.0'
    );
} );

Load a custom block's JS registration file, editor-only.

Real case

add_action( 'enqueue_block_editor_assets', function() {
    if ( 'post' !== get_current_screen()->post_type ) {
        return;
    }
    wp_enqueue_script( 'my-post-only-sidebar', get_template_directory_uri() . '/js/sidebar.js' );
} );

Load a sidebar plugin script only on the Post editor, not other post types or the site editor.

Common Use Cases

  • Load custom block registration JS
  • Add editor-only CSS for custom blocks
  • Register a Gutenberg sidebar plugin
  • Load third-party editor extensions

Common mistakes

  • Using this hook to load assets meant for the front-end — it never fires there; use wp_enqueue_scripts or enqueue_block_assets instead

Related hooks

FAQ

Does enqueue_block_editor_assets also run on the front-end for block themes (FSE)?

No — this hook is editor-only, even in a block theme. For assets needed both in the editor and on the front-end (e.g. a block's own styling), use enqueue_block_assets instead.

Source: wp-includes/script-loader.php

Group wizard

One session: this hook, then each related_hooks entry. Walk it and tell us what to change.

enqueue_block_editor_assets → wp_enqueue_scripts → enqueue_block_assets

functions.php — enqueue_block_editor_assets
functions.php
PHP enqueue_block_editor_assets · Hook 1 of 3 · Step 1 of 7

Practice the enqueue_block_editor_assets WordPress action hook in our interactive sandbox — a VS Code-style editor with a step-by-step enqueue_block_editor_assets tutorial, add_action exercises, and instant feedback. No local WordPress install required.