Support

Account

Home Forums Front-end Issues How to get a Block’s JS Script in header?

Unread

How to get a Block’s JS Script in header?

  • Hey guys!

    I am just finishing a website, and with one feature I built as an ACF Gutenberg Block (in a plugin), I realized that it would be probably advantageous if the script sits in the header. If the script gets loaded late, it sometimes shows all videos below each other instead of just displaying them one after the other.

    Now I know that, when registering a script the WP way via wp_enqueue_script, I just can change the last parameter to false and it’s in the header. So I found out, that while registering the Block, I can also use enqueue_assets instead of enqueue_script as a parameter to put the assets in an array via wp_enqueue_script. So my code looks like this – it works fine, except for it ignoring the false parameter in the end. Does anyone of you have an idea? Any help is much appreciated!

    acf_register_block_type(array(
                'name' 	        => 'videosliderslider',
                'title'             => __('Videoslider'),
                'description'       => __('Ein Slider, um mehrere Videos hintereinander abzuspielen'),
                'post_types' 		=> array( 'page' ),
                'render_template'   => FP_PLUGIN_PATH . 'blocks/videoslider/videoslider.php',
                'category'          => 'Media',
                'icon'              => 'admin-users',
                'mode'              => 'edit',
                'enqueue_assets'	=> function(){
                    wp_enqueue_style( 'videoslider', FP_PLUGIN_URI . 'blocks/videoslider/videoslider.css', array(), null, 'all' );
                    wp_enqueue_script('videoslider', FP_PLUGIN_URI . 'blocks/videoslider/videoslider.js', array(), '1.0.0', false );
                },
            ));
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.