Hi, I’m building my first ACF blocks. The acf_register_block_type() lets you add an ‘enqueue_style’ option, but the styles are applied both to frontend and backend, and that’s not what I want.
I can add only forntend styles simply adding them to my regular style files, without using acf_register_block_type. Good.
But how can I add only-admin styles? Is there a way?
Thank you
I can answer by myself.
To load styles only for backend, you can use the enqueue_block_editor_assets action:
add_action('enqueue_block_editor_assets','add_block_editor_assets',10,0);
function add_block_editor_assets(){
wp_enqueue_style('block_editor_css', [yourpath] . '/editor-blocks.css');
}
This was exactly what I was looking for, had the same question. Just one thing: Your method has as a downside that it now loads on every post editor, even if the specific block for which the style or script is is not used.
Is there a way to make it conditional on a specific custom ACF block being used?
Mmm I don’t know: developers here could give some help 🙂 Toc toc? Hey there! 🙂
Don’t you get Cannot modify header information warning with this function ??