I’m using the following in PHP to register my custom block:
register_block_type( __DIR__, /* block.json */
array(
'render_callback' => 'render_my_block',
'script' => 'my-custom-js',
)
);
The block is registered but the my-custom-js
JS file is loaded on the frontend and in the backend editor. How can I load it only on the frontend?
I tried 'view_script' => 'my-custom-js'
and 'view-script' => 'my-custom-js'
but it does not work.
I know that I can use is_admin()
to check if it’s in the editor and not load a js file but I’m trying to see how it can be done with register_block_type()
.