Home › Forums › Gutenberg › js fires before block is rendered › Reply To: js fires before block is rendered
@yueng actually, the wp_enqueue_script, when included in the enqueue_assets part of acf_register_block should include it in the frontend and backend for your block, here’s what mine looks like:
...
'enqueue_assets' => function(){
//Stack the Assets in the Order we Need Them
wp_enqueue_style( 'slideshow-block-style', get_template_directory_uri() . '/template-parts/block/css/slideshow.css', array('general-block-style') ); //Requires all-blocks.css
wp_enqueue_style( 'slick-main', get_template_directory_uri() . '/template-parts/block/css/slick/slick.css' );
wp_enqueue_style( 'slick-theme', get_template_directory_uri() . '/template-parts/block/css/slick/slick-theme.css' );
wp_enqueue_script( 'slideshow-block-library', get_template_directory_uri() . '/template-parts/block/js/slick.min.js', array('jquery'), '', true );
wp_enqueue_script( 'slideshow-block-script', get_template_directory_uri() . '/template-parts/block/js/slideshow.js', array('jquery'), '', true );
},
...
Also, I took a second look at my slideshow javascript and the only real difference I have is an each jQuery function (which might help):
$(document).ready(function(){
$('.banners').each(function(){
init_banner( $(this) );
});
});
Let me know if that helps.
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.