Hi,
I need to put the script on the Gutenberg and on the frontend. How can I understand this behavior?
acf_register_block( array(
'name' => 'my-custom',
//...
'enqueue_assets' => function () {
wp_enqueue_style('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');
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');