Home Forums Gutenberg Enqueue_style but only once for all blocks


Enqueue_style but only once for all blocks

  • Hello!

    First of all, i love your ACF blocks concept, but i have one question, can i include only ONCE for example main.css for ALL blocks? And if i can, where can i do this?

    Thank you!

  • 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.

  • This is awesome! Thank you 🙂

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Enqueue_style but only once for all blocks’ is closed to new replies.