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
?