Support

Account

Home Forums Gutenberg Enqueue_style but only once for all blocks Reply To: Enqueue_style but only once for all blocks

  • I needed to include a common CSS file for all of my blocks and I was able to do it with this:

    function enqueue_foundation_in_admin() {
    	$current_screen = get_current_screen();
        if ( method_exists( $current_screen, 'is_block_editor' ) && $current_screen->is_block_editor() ) {//Check if we're on a Gutenberg Page
        	wp_enqueue_style( 'foundation', get_template_directory_uri() . '/scripts/foundation-6.5.1.css' );
        }
    }
    add_action( 'admin_enqueue_scripts', 'enqueue_foundation_in_admin' );

    Note: this could effect other items in the WordPress admin (text, divs etc.), so be cognizant of that. Otherwise the alternative is using “enqueue_assets” and wp_enqueue_style and just declaring the CSS file for each block.