Is there anyway to prevent the enqueued style used to render blocks in the backend from being loaded in the frontend?
I have some blocks where styles are repeated, but some are created using an ACF repeater, and some from a custom ACF Block, which means I’m needing to repeat the same code in the main theme stylesheet as well as the separate enqueued style.
I can remove the enqueue for the custom blocks, but then they don’t look great when editing.
use conditional if ( $is_preview ) { ... }
or is_admin()
Both should work fine inside 'enqueue_assets' => function() { ... }
when registering the block with api 1 (not acf 6.0)
@uxbox unfortunately ‘enqueue_assets’ currently works not correct from gutenberg css iframe attachment perspective.
How about unload it with wp_dequeue_style?
The second option is to make it with wp_deregister_style.
if( ! is_admin() ) {
add_action( 'wp_enqueue_scripts', 'my_dequeue_style', 11 );
function my_dequeue_style() {
wp_dequeue_style( 'my-handle' ); // the handle of style of the block
}
}
Another thing… If You want to style the blocks & controls – why not just make css file for it and just add it to backend like:
add_action('admin_head', 'my_custom_acf_styles');
function my_custom_acf_styles() {
echo '<style>
.my-field-class {
font-family: "Lucida Grande";
font-size: 12px;
}
</style>';
}
This worked for me (in part):
add_filter( 'should_load_separate_core_block_assets', '__return_true' );
Edit:
It doesn’t fix the issue completely. Still loads assets for blocks that are used on the page.
You must be logged in to reply to this topic.
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.