I'm trying to make a Custom Gutenberg Block, but I'm having trouble with loading javascript that goes with this block.

On the front-end it works fine, but in the editor it seems that the script fires (even with DOMcontentloaded or window.onload) BEFORE the Gutenberg block itself is fully loaded.

Since my script targets an element in the block (which it can't find because the element hasn't loaded yet), it's not working correctly.

Any suggestions on how to make the script load AFTER the Custom Block has loaded fully in the editor?

(I'm using the ACF way of creating Custom blocks)


I think the better way to solve this is having your scripts related to your block directly inside your edit function. Then, you can create a separated file for your frontend scripts. Enqueue this frontend.js file in the footer.



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.