Last active
July 7, 2022 15:39
-
-
Save schlotterer/68cb969b590d4eb03ddb452e87f06d62 to your computer and use it in GitHub Desktop.
Sample block registration.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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