Home › Forums › Gutenberg › Enqueue Scripts for ACF Block Preview › Reply To: Enqueue Scripts for ACF Block Preview
Hey @inhouse ,
I know I’m late to the party, but had a bit of a hard time getting my head around previews as well and found out how to cope with it.
You can enqueue your styles and/or scripts like so:
acf_register_block_type(array(
// your other arguments
'enqueue_assets' => 'blockname_assets',
));
and then have a conditional enqueue like this:
// Enqueue scripts & styles if frontend
function blockname_assets() {
// Frontend loading
if(!is_admin()) {
wp_enqueue_style('blockname', get_template_directory_uri() . '/css/blockname.min.css' );
wp_enqueue_script('blockname', get_template_directory_uri() . '/js/blockname.js', array(), '', true );
}
}
and extend it, so that different enqueues are happening for backend and frontend. Does that help you already 🙂 ?
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.