I couldn’t find a built in ACF way of doing this.
Instead, in my block’s PHP render function I added
printf( "<script>window.jQuery(window).trigger('acf/loaded/block-name');</script>" );
This uses jQuery as an event bus to trigger an event when the block is rendered. You might need to include a check that you’re in the admin so the event won’t be triggered in the frontend. My WordPress is headless so this wasn’t an issue for me.
Then, in your JavaScript, you can do:
$( window ).on( 'acf/loaded/block-name', function() {
// rest of your code here
} )
By including the block name in the event you can check different events for individual blocks.
Related Posts:
- When using the block.getSaveElement hook can you output different markup based on whether or not you are in the edit view or the live page view?
- Multi color post title by using custom javascript inside the gutenberg editor?
- Running Gutenberg React in Development Mode
- add button to post edit page when post_status=publish
- Is it possible to use Gutenberg on the front-end?
- simple expandable vertical menu, java script problem
- Add a containing DIV to core Gutenberg blocks
- Gutenberg Blocks – Attributes from comment delimiter or from HTML?
- How to use get_option() without any filter?
- dynamic external javascript generated using php
- Widget Javascript code (ajax)
- Gutenberg: How to mix dynamic and static output?
- How to get value of selected page template in Gutenberg editor?
- What values can we use in `formattingControls` parameter in RichText component
- How to link external JavaScript files?
- Limiting allowed html elements/strip harmful scripts from editor
- Create default_content layout template based on post id
- add JS to multiple plugin admin pages
- How to use
- Create simple Cookie Box for WordPress
- how to add custom css and js on wordpress post editor directly without using .php file
- Javascript Solution Remove Specific Tag but leave the rest in a specific DIV
- window resizing problem
- How to get custom page template being edited in gutenberg editor
- Gutenberg block outputting JSON in front end – is this normal?
- Load MediaPlayerElement after Infinity Scroll loads more posts
- How can I use a Tiny MCE editor in my custom Gutenberg block?
- Include custom JS without child theme
- How can I have a common background color across multiple WordPress blocks?
- Custom Login Process
- find out reason of “Updating failed” in Post-editor
- How to create “custom page types” with different custom fields in them?
- Upload a web module (html and JS) to wordpress
- How to add WordPress JS Script Links
- custom css and javascript not working on page defined as template?
- wp_enqueue_script JS code runs too late (after user begins interacting)
- Created Custom Block – When I come back to edit post/page and change my block content – Update button stays disabled
- Cannot read properties of undefined (reading ‘show_ui’) Error on WordPress Post Editor
- Custom default settings for WP native Gallery Block
- Will WordPress updates remove Gutenberg Additional Classes?
- custom email validation using javascript api with elementor pro and code snippets
- javascript file not working in a plugin template file
- adding fade on mouseover to images
- Is it possible to edit a wordpress category with Gutenberg?
- wp.blocks.registerBlockType not showing what I want on the frontend
- Javascript Tooltip not fully working on my wordpress page
- Where to put coding a validation script for store? [duplicate]
- WordPress Customizer: Check for value of CSS selector and replace it
- How to submit form data in the same page in WordPress without reloading the page?
- how to auto fille conatct form 7 when user is logined
- How to implement custom Javascript to my site
- Multi-site customization
- Pass the post ID
- Document.body.scrollTop in WordPress
- Adding Custom HTML/CSS/JS code in specific page
- Making custom pages (with an example to explain the goal)
- Prevent posts from being published if the ‘Uncategorized’-category or no category is selected
- How do I add custom CSS animations for specific Gutenberg blocks?
- Particle.js not loading in WordPress Gutenberg
- Customise “Add a New Post” page
- How to use standalone Gutenberg (block editor) instance on any my own admin page in WordPress
- How to disable the PDF preview in the file block by default
- How do I disable shortcuts in WordPress?
- How do i get custom fontSizes and theme fontSizes?
- Create a uniqueId when a block is created or copied
- How to detect if we are in the Site Editor part of the Block Editor (as opposed to editing a Page/Post) in JavaScript?
- How can I show a Slot/Fill in the block editor
- Some data of one custom user profile is erased when I update another custom user profile
- Is it possible to add javascript to template parts
- How to add a new attribute to core wp block editor without npm?
- Change in credit card payment button for woocommerce
- Notify/check if the content of a custom gutenberg block has changed on save_post
- Custom Search on media files PDF images pages posts
- How to add more elements to an already existing section in Gutenberg
- How do i get an Inline style in Gutenberg Block show up in front end?
- Custom Menu (only showing direct cildren) ACF not showing
- wordpress categories narrow down results
- WordPress adds and tags into HTML blocks after saving
- Is it bad practice to add a filter within a filter in wordpress?
- Local WordPress installation feeding multiple online site sites
- Modifying posts based on category in TwentyTwentyTwo theme
- wordpress 6.2 is alignfull and lignwide removed?
- Permalink Listing WordPress
- Redirection after Category Change for Custom Structure
- How to display product variations on same row
- Has the table name in SQL for WordPress changed from WP_posts to WPCS_post?
- Why after customizing Home Page, the site is loading six missing blob sources, slowing down all site?
- Create a page for each database table entries
- Add custom styles to the Raft theme
- When trying to run build script with gutenberg (with SVG import) – Error: Plugin name should be specified
- Gutenberg core/file add style support in js/ json
- Where did I put this one line of css?
- Custom product sorting archive page
- Reinitiate Gutenburg’s blocks using javascript
- Add custom information in editor summary
- Vanilla javascript in custom gutenberg block not working
- A Voting system for a pageants
- Working with a non-React external library in a custom block
- Create Youtube embed block with createBlock
- Insert text programmatically in WordPress Gutenberg Editor