Skip to content

Instantly share code, notes, and snippets.

@nicooprat
Last active October 22, 2018 16:42
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 nicooprat/cb11263eb9151578b068e1cff5983979 to your computer and use it in GitHub Desktop.
Save nicooprat/cb11263eb9151578b068e1cff5983979 to your computer and use it in GitHub Desktop.
Create an ACF block
function my_acf_block_render_callback( $block ) {
$slug = str_replace('acf/', '', $block['name']);
if( file_exists(STYLESHEETPATH . "/template-parts/block/content-{$slug}.php") ) {
include( STYLESHEETPATH . "/template-parts/block/content-{$slug}.php" );
}
}
add_action('acf/init', function() {
if( function_exists('acf_register_block') ) {
acf_register_block(array(
'name' => 'testimonial',
'title' => __('Testimonial'),
'render_callback' => 'my_acf_block_render_callback',
'category' => 'formatting',
));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment