Skip to content

Instantly share code, notes, and snippets.

@schlotterer
Last active July 7, 2022 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schlotterer/68cb969b590d4eb03ddb452e87f06d62 to your computer and use it in GitHub Desktop.
Save schlotterer/68cb969b590d4eb03ddb452e87f06d62 to your computer and use it in GitHub Desktop.
Sample block registration.
acf_register_block_type(array(
‘name’ => ‘custom-block’,
‘title’ => __(‘Custom Block’),
‘description’ => __(‘A custom block.’),
‘render_template’ => get_template_directory() . ‘/template-parts/blocks/custom-block/custom-block.php’,
// Basic style enqueue
'enqueue_style' => get_template_directory_uri() . '/template-parts/blocks/custom-block/custom-block.css',
// Basic Script enqueue
'enqueue_script' => get_template_directory_uri() . '/template-parts/blocks/custom-block/custom-block.js',
// Broad use enqueue_assets
// Specifying a function name
‘enqueue_assets’ => ‘my_acf_block_enqueue_assets’,
// Specifying a class method
‘enqueue_assets’ => array($this, ‘block_enqueue_assets’),
// Specifying an anonymous function
‘enqueue_assets’ => function(){
wp_enqueue_style( ‘custom-block’, get_template_directory_uri() . ‘/template-parts/blocks/custom-block/custom-block.css’ );
wp_enqueue_script( ‘custom-block’, get_template_directory_uri() . ‘/template-parts/blocks/custom-block/custom-block.js’, array(‘jquery’), ”, true );
},
));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment