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 do i get custom fontSizes and theme fontSizes?
- How to get the Date Format and Time Format settings for use in my template?
- Blocks: set a default value for a TextControl
- Custom taxonomy: same terms, but for different years
- Can I use $wpdb for my custom tables in the WordPress database?
- How to get input_attrs in the sanitize function?
- What is WordPress file encoding?
- Change from /wp-admin/ to something else?
- Allow comments without approval for custom content type
- Add ‘Right Now’ widget to custom dashboard
- Are there any security issues with setting the WP_INSTALLING constant to true?
- Naming script handles right way
- How to edit pages after installing WP
- Multiple WordPress outside wordPress installation?
- WordPress generated links – menus and home_url() – not using https despite settings
- Using wp.data.select get actual tags (not id’s) used in post
- How to check if a custom user profile field is empty
- Programatically update posts in database from one block to another using transform
- What is the best way to move a single site from one MS installation to another? [duplicate]
- Don’t change Custom Post Type slug to unique value
- Gutenberg getBlockIndex in save() function
- Widgets and Post/Page edit/new blank, console errors only, no server errors
- Shop page custom buttons which is visible to only administrator
- Insert menu with a custom walker into page / post body using shortcode?
- Woocommerce custom field calculation
- How to auto add nofollow to links in custom field?
- How to load a mycred hook from a plugin?
- toggle Multiple Loop with tittle
- How To make Custom page of every Category
- Global theme customization multisite
- Floating CTA Image Integration
- Altered Media Library URLs
- Admin menu disable new/delete page
- How to loop through 1 CPT with 2 Taxonomies
- retrieve theme custom settings
- pull custom fields values from wp-database in a nested foreach loop
- Custom CSS File wont work on second Page
- How to create a shortcode with HTML code in it and custom parameters/
- How can i move my product name & price from below thumbnail to be the rollover content in Avada & Woocommerce?