do_action( ‘enqueue_block_assets’ )

Fires after enqueuing block assets for both editor and front-end.

Description

Call add_action on any hook before ‘wp_enqueue_scripts’.

In the function call you supply, simply use wp_enqueue_script and wp_enqueue_style to add your functionality to the Gutenberg editor.

Source

do_action( 'enqueue_block_assets' );

Changelog

VersionDescription
5.0.0Introduced.

User Contributed Notes

  1. Skip to note 3 content

    From version 6.3 onwards, styles and scripts added using enqueue_block_assets() will be enqueued for the editor iframe. If the intention is to limit styles to the editor only, simply use the is_admin() condition. Example:

    /**
     * Register and enqueue stylesheet for the editor only.
     */
    add_action( 'enqueue_block_assets', 'wpdocs_enqueue_editor_styles' );
    
    function wpdocs_enqueue_editor_styles() {
        if ( is_admin() ) {
            wp_enqueue_style( 'prefix-style', plugins_url( 'style.css', __FILE__ ) );
        }
    }
  2. Skip to note 4 content
    function wpdocs_mytheme_block_styles() {
        wp_enqueue_style( 'testimonial',  get_stylesheet_directory_uri() . '/template-parts/blocks/testimonial/testimonial.css' );
        wp_enqueue_script( 'testimonial',  get_stylesheet_directory_uri() . '/template-parts/blocks/testimonial/testimonial.js' );
    }
    add_action( 'enqueue_block_assets', 'wpdocs_mytheme_block_styles' );

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