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
- Prevent WordPress from automatically installing a new theme each year
- Can we use one WordPress installation for multiple databases, domains and content directories
- How to filter get_avatar?
- Multiple content areas per page
- CSS rules that the theme gets from a function
- How to rotate the header image per day?
- How to show only Standard Format post in my custom taxonomy page -wordpress 3.8.1
- WooCommerce Checkout page customization [closed]
- Adding extra info via GET while registeration in wordpress
- Get term by slug in Gutenberg
- How can I add data to a custom column in the Users section of the wordpress backend?
- Passing select control value to block
- Last post is not showing up
- Gutenberg RichText
- Volume mounts when setting up WordPress with docker [closed]
- Include user defined styles without including wp-load
- Preserve custom URL parameter after saving post
- Best practice – pages – ACF or inline coding
- wpdb custom tables without plugin
- GeoMashup plugin: how to customize cluster markers / icons? [closed]
- Looping over wordpress meta to create “ ‘s?
- Combine multiple getEntityRecords calls
- Add a searchbox to the body of a page
- How to put a site offline, including images?
- How to add css option to Header Image customizer?
- Woocommerce custom archive page custom content and shortcode
- Page flickers in customization mode
- We are facing this error in header unable to understand the issue
- When is the wp-settings-[time] cookie generated?
- Hide entry-header for a specific category
- How Can I add show_post_count in get_archives_link?
- Trouble with custom login page
- admin aoolbar add_node() and pulling in my post slug
- Custom Form Input not saving to Database
- How to create 2 preview button in a post?
- Custom terms in custom category taxonomy
- Setting Custom WordPress “Posts page” AS “Front page”
- Instead of Custom CSS Theme CSS is loading
- I need to make the title of the page dynamic in my custom plugin
- Custom CSS working on home page but not on NEW created PAGE
- Custom Menu (only showing direct cildren) ACF not showing