Home › Forums › Gutenberg › Where put wp_register_script to enqueue in acf_register_block › Reply To: Where put wp_register_script to enqueue in acf_register_block
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.