Support

Account

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 🙂 ?