Skip to content

Instantly share code, notes, and snippets.

@SteveJonesDev
Created March 30, 2023 15:06
Show Gist options
  • Select an option

  • Save SteveJonesDev/6e9bc324c10837c20fa5b87f59080e9f to your computer and use it in GitHub Desktop.

Select an option

Save SteveJonesDev/6e9bc324c10837c20fa5b87f59080e9f to your computer and use it in GitHub Desktop.
Advanced Custom Fields Block Javascript
(function($){
/**
* initializeBlock
*
* Adds custom JavaScript to the block HTML.
*
* @date 10/11/21
* @since 1.0.0
*
* @param object $block The block jQuery element.
* @param object attributes The block attributes (only available when editing).
* @return void
*/
var initializeBlock = function( $block ) {
}
// Initialize each block on page load (front end).
$(document).ready(function(){
$('.callout-block').each(function(){
initializeBlock( $(this) );
});
});
// Initialize dynamic block preview (editor).
if( window.acf ) {
window.acf.addAction( 'render_block_preview/type=callout-block', initializeBlock );
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment