I have the same code and it works for me. The js file appears in the footer (back-end/gutenberg and front-end). Maybe try this:
function my_init() {
wp_register_style( 'team', get_template_directory_uri() . '/dist/blocks/css/team.css', array(), filemtime( get_template_directory() . '/dist/blocks/css/team.css' ), 'all' );
wp_register_script( 'team', get_template_directory_uri() . '/dist/blocks/js/team.js', array( 'jquery', 'application' ), filemtime( get_template_directory() . '/dist/blocks/js/team.js' ), true );
}
add_action('init', 'my_init');
// acf_register_block_type:
'enqueue_assets' => function () {
wp_enqueue_style( 'team' );
wp_enqueue_script( 'team' );
},
I’m just learning the Gutenberg editor and I might be wrong, but it seems to me that inside the initializeBlock function you can only operate on the $block variable. Try this:
var initializeBlock = function( $block ) {
$testimonials = $block.find('.testimonials');
$testimonials.slick();
}
Hi,
Did you create js code following these guidelines?
https://www.advancedcustomfields.com/resources/acf_register_block_type/
Section: “Adding block scripts” -> testimonial.js
There was an error in the code above. Below is the correct one:
acf_register_block( array(
'name' => 'my-custom',
//...
'enqueue_assets' => function () {
wp_enqueue_script('my-script');
}
));
function my_function() {
wp_register_script('my-script', get_template_directory_uri() . '/js/my-script.js', array(), '1.0.0', true);
}
// The script is placed only on the frontend - OK
add_action('wp_enqueue_scripts', 'my_function');
// The script is placed only on the frontend - Why?
add_action('enqueue_block_assets', 'my_function');
// It works! The script is placed on the Gutenberg and on the frontend
add_action('init', 'my_function');
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.