A drag-and-drop editor to create “Field Groups” — sets of form fields that appear within specific areas of the WordPress Admin
<?php
// e.g. /wp-content/themes/my-custom-theme/single.php
if ( have_posts() ) :
while ( have_posts() ) : the_post();
the_title();
the_content();
the_field( 'my-custom-field-slug' );
endwhile;
endif;
?>
<?php
//e.g. wp-content/themes/my-theme/functions.php
acf_register_block_type(array(
'name' => 'my-block',
'title' => __('My Block'),
'description' => __('A custom block type.'),
'render_template' => 'hello.php',
));
<?php
//e.g. wp-content/themes/my-theme/hello.php
echo '<h1>Hello</h1>';
<?php
//e.g. wp-content/themes/my-theme/hello.php
echo '<h1>Hello ' . get_field( 'person' ) . '</h1>';
<?php
acf_register_block_type(array(
'name' => 'custom-block',
'title' => __('Custom Block'),
'description' => __('A custom block.'),
'category' => 'layout',
'icon' => 'slides',
'keywords' => array( 'slide' ),
'align' => 'full',
'supports' => array(
'align' => array( 'center', 'wide', 'full' ),
)
));
<?php
acf_register_block_type(array(
'name' => 'custom-block',
'title' => __('Custom Block'),
'description' => __('A custom block.'),
'render_callback' => 'my_render_function',
));
function my_render_function($block, $content = '', $is_preview = false) {
$block_name = explode('/', $block['name'])[1];
echo '<div class="wp-block wp-block-' . $block_name . '">';
include( __DIR__ . 'template-parts/blocks/' . $block_name . '.php' );
echo '</div>';
}
function my_enqueue_editor_assets() {
wp_enqueue_style( 'editor-styles', get_stylesheet_directory_uri() . '/editor.css' );
}
add_action( 'enqueue_block_editor_assets', 'my_enqueue_editor_assets' );
<?php
global $post
$blocks = parse_blocks( $post->post_content );
$table_of_contents = array();
foreach($blocks as $block) {
$table_of_contents[] = $block['blockName'];
}