Quantcast
Channel: WordPress.org Forums » All Topics
Viewing all articles
Browse latest Browse all 59525

Gutenberg Script Loading

$
0
0

Replies: 0

So im following the way to add styles/script in to the gutenberg editor as mentioned here:
https://jasonyingling.me/enqueueing-scripts-and-styles-for-gutenberg-blocks/

Styles are coming in fine as expected, however scripts dont seem to be working as expected (possibly too early?).

The code being used is:

/**
 * Enqueue block JavaScript and CSS for the editor
 */
function my_block_plugin_editor_scripts()
{
    // Enqueue block editor styles
    wp_enqueue_style('fontawesome', 'https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css');
    wp_enqueue_style('site-css', get_template_directory_uri() . '/assets/styles/style.css', array(), filemtime(get_template_directory() . '/assets/styles/scss'), 'all');
    wp_enqueue_style('slick-css', '//cdn.jsdelivr.net/npm/slick-carousel@1.8.1/slick/slick.css');
    wp_enqueue_style('slick-theme-css', 'https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.9.0/slick-theme.min.css');

    // Enqueue block editor JS
    wp_enqueue_script('site-js', get_template_directory_uri() . '/assets/scripts/scripts.js', array('jquery'), filemtime(get_template_directory() . '/assets/scripts/js'), true);
    wp_enqueue_script('slick-js', 'https://cdn.jsdelivr.net/npm/slick-carousel@1.8.1/slick/slick.min.js', array('jquery'), true);
}

// Hook the enqueue functions into the editor
add_action('enqueue_block_editor_assets', 'my_block_plugin_editor_scripts');

(Neat version here if formatting is off: https://pastebin.com/BfHpmmgW )

I can see in devtools that its adding all scripts in to the <Head>.

So, is the issue that its loading too early?
If so, how can i make it load later?

Thanks


Viewing all articles
Browse latest Browse all 59525

Trending Articles