Support

Account

Home Forums Gutenberg acf_register_block_type > enqueue_stuff

Solved

acf_register_block_type > enqueue_stuff

    • philby

    • June 6, 2019 at 4:38 pm

    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)

    • philby

    • June 14, 2019 at 7:33 pm

    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.

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

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.