Support

Account

Home Forums Gutenberg acf_register_block_type > enqueue_stuff

Solved

acf_register_block_type > enqueue_stuff

  • I’m certainly missing something perfectly obvious, but so far I’ve not been able to get ACF to load any CSS or JS files with my blocks.

    I’m defining path constants in a plugin

    if ( !defined( 'WH_PLUGIN_PATH' ) ) {
        define( 'WH_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );
    }
    if ( !defined( 'WH_PLUGIN_URI' ) ) {
        define( 'WH_PLUGIN_URI', plugin_dir_url( __FILE__ ) );
    }

    and then include a block’s code
    include( WH_PLUGIN_PATH . 'blocks/agendaselect/agendaselect.php');

    That’s where I actually register the block

    // register the agenda block
    acf_register_block_type(array(
        'name'              => 'agendaselect',
        'title'             => __('Agenda'),
        (…)
        'render_template'   => WH_PLUGIN_PATH . '/blocks/agendaselect/template-agendaselect.php',
        'enqueue_style'     => WH_PLUGIN_URI . 'blocks/agendaselect/agendaselect.css',
    ));

    The render template is working without a problem, but no CSS file is ever loaded.
    Echoing the CSS file path in the render template gives the working CSS URI
    echo constant("WH_PLUGIN_URI") . 'blocks/agendaselect/agendaselect.css' –>
    https://clientsite.test/wp-content/plugins/client-plugin/blocks/agendaselect/agendaselect.css
    but the CSS is not loaded, neither in the editor nor in the frontend, as far as I can see.

    Did I miss something obvious around how enqueue_style is supposed to work inside acf_register_block_type?

  • I do have exactly the same issues. Any solutions, any suggestions for this?
    (WP 5.2.1, ACF 5.8.0)

  • Actually, the solution was embarrassingly simple and obvious: for some reason ACF hadn’t updated from 5.8b4 to the lastest stable version.
    When I noticed yesterday, I updated manually to 5.8.1, and now everything seems to work brilliantly, as is customary with ACF.

  • I updated to 5.8.1, but unfortunatly it didn’t solve the problem.

  • Did you try to echo the CSS location in the render template? Does it give a valid URL?

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

The topic ‘acf_register_block_type > enqueue_stuff’ is closed to new replies.