Last active
October 22, 2018 16:42
-
-
Save nicooprat/cb11263eb9151578b068e1cff5983979 to your computer and use it in GitHub Desktop.
Create an ACF block
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
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" ); | |
} | |
} |
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
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