Home Forums Gutenberg ACF Blocks – Prevent Style load in Frontend?


ACF Blocks – Prevent Style load in Frontend?

  • Is there anyway to prevent the enqueued style used to render blocks in the backend from being loaded in the frontend?

    I have some blocks where styles are repeated, but some are created using an ACF repeater, and some from a custom ACF Block, which means I’m needing to repeat the same code in the main theme stylesheet as well as the separate enqueued style.

    I can remove the enqueue for the custom blocks, but then they don’t look great when editing.

  • use conditional if ( $is_preview ) { ... } or is_admin()
    Both should work fine inside 'enqueue_assets' => function() { ... } when registering the block with api 1 (not acf 6.0)

  • @uxbox unfortunately ‘enqueue_assets’ currently works not correct from gutenberg css iframe attachment perspective.

  • How about unload it with wp_dequeue_style?
    The second option is to make it with wp_deregister_style.

    if( ! is_admin() ) {
       add_action( 'wp_enqueue_scripts', 'my_dequeue_style', 11 );
       function my_dequeue_style() {
          wp_dequeue_style( 'my-handle' ); // the handle of style of the block
  • Another thing… If You want to style the blocks & controls – why not just make css file for it and just add it to backend like:

    add_action('admin_head', 'my_custom_acf_styles');
    function my_custom_acf_styles() {
      echo '<style>
        .my-field-class {
          font-family: "Lucida Grande";
          font-size: 12px;
  • This worked for me (in part):
    add_filter( 'should_load_separate_core_block_assets', '__return_true' );

    It doesn’t fix the issue completely. Still loads assets for blocks that are used on the page.

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

You must be logged in to reply to this topic.