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.
Did you try to echo the CSS location in the render template? Does it give a valid URL?
The topic ‘acf_register_block_type > enqueue_stuff’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.