Skip to content

Instantly share code, notes, and snippets.

@lgladdy
Created October 7, 2022 08:31
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 lgladdy/9711fa76969a438572b5346faf243086 to your computer and use it in GitHub Desktop.
Save lgladdy/9711fa76969a438572b5346faf243086 to your computer and use it in GitHub Desktop.
//block.json
{
"name": "simple-test-block",
"title": "Simple Test Block",
"description": "Simple Test Block",
"category": "theme",
"icon": "admin-comments",
"acf": {
"mode": "preview",
"renderTemplate": "render.php"
}
}
//load.php
<?php
add_action( 'init', 'stb_register_acf_blocks', 5 );
function stb_register_acf_blocks() {
register_block_type( __DIR__ );
}
add_action( 'acf/include_fields', 'stb_register_php_fields' );
function stb_register_php_fields() {
if ( function_exists( 'acf_add_local_field_group' ) ) :
acf_add_local_field_group(
array(
'key' => 'group_633fe2980a496',
'title' => 'Simple Test Block',
'fields' => array(
array(
'key' => 'field_633fe298f7b2e',
'label' => 'Text Field',
'name' => 'text_field',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'maxlength' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
),
),
'location' => array(
array(
array(
'param' => 'block',
'operator' => '==',
'value' => 'acf/simple-test-block',
),
),
),
'menu_order' => 0,
'position' => 'normal',
'style' => 'default',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => '',
'active' => true,
'description' => '',
'show_in_rest' => 0,
)
);
endif;
}
//render.php
<div>
<h4>Simple Test Block</h4>
<p><?php the_field( 'text_field' ); ?></p>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment