Dynamic Block Types

The Dynamic Block Types module allows you to register and manage ACF Block Types from your WordPress admin, in ACF > Block Types menu.

All ACF settings can be set within the UI. See ACF Block Types documentation.

Dynamic Block Type

(String) A unique name that identifies the block (without namespace).
Note: A block name can only contain lowercase alphanumeric characters and dashes, and must begin with a letter.

(String) (Optional) This is a short description for your block.

(String) Blocks are grouped into categories to help users browse and discover them. The core provided categories are [ common | formatting | layout | widgets | embed ]. Plugins and Themes can also register custom block categories.

(Array) (Optional) An array of search terms to help user discover the block while searching.
One line for each keyword. ie:

quote
mention
cite

(Array) (Optional) An array of post types to restrict this block type to.

(String) (Optional) The display mode for your block. Available settings are “auto”, “preview” and “edit”. Defaults to “auto”.

auto: Preview is shown by default but changes to edit form when block is selected.
preview: Preview is always shown. Edit form appears in sidebar when block is selected.
edit: Edit form is always shown.

Note. When in “preview” or “edit” modes, an icon will appear in the block toolbar to toggle between modes.

(String) (Optional) The default block alignment. Available settings are “left”, “center”, “right”, “wide” and “full”. Defaults to an empty string.

Simple: Specify a Dashicons class or SVG path
Colors: Specify colors & Dashicons class

(String) (Optional) An icon property can be specified to make it easier to identify a block. These can be any of WordPress’ Dashicons, or a custom svg element.

Specifying a background color to appear with the icon e.g.: in the inserter.

Specifying a color for the icon (optional: if not set, a readable color will be automatically defined)

Specifying a dashicon for the block

(String) The path to a template file used to render the block HTML. This can either be a relative path to a file within the active theme or a full path to any file.

(Callable) (Optional) Instead of providing a render_template, a callback function name may be specified to output the block’s HTML.

(String) (Optional) The url to a .css file to be enqueued whenever your block is displayed (front-end and back-end).

(String) (Optional) The url to a .js file to be enqueued whenever your block is displayed (front-end and back-end).

(Callable) (Optional) A callback function that runs whenever your block is displayed (front-end and back-end) and enqueues scripts and/or styles.

This property adds block controls which allow the user to change the block’s alignment. Defaults to true. Set to false to hide the alignment toolbar. Set to an array of specific alignment names to customize the toolbar.

Set to an array of specific alignment names to customize the toolbar.
One line for each name. ie:

left
right
full

Enable inner block feature. Defaults to false.

Set the "xy" position of content using a 3×3 matrix grid. Defaults to false.

Specifies the default attribute value.

This property allows the user to toggle between edit and preview modes via a button. Defaults to true.

This property allows the block to be added multiple times. Defaults to true.

Export/Import Block Types

It is possible to export and import Block Types in a Json file using the ACF > Tools menu. Block Types can also be exported in PHP format, to manually register them in the functions.php file. Those tools are also available directly within the Dynamic Block Types UI.

Settings in PHP

The Dynamic Block Types UI use the acf_register_block_type() function behind the scene. It is possible to change the settings in PHP using the acf/register_block_type_args hook. See documentation. Usage example:

/*
 * acf/register_block_type_args
 * 
 * https://www.advancedcustomfields.com/resources/acf-register_block_type_args/
 */
add_filter('acf/register_block_type_args', 'my_acf_register_block_type_args');
function my_acf_register_block_type_args($args){
    
    if($args['name'] !== 'acf/my-block-type')
        return $args;
    
    $args['render_template'] = '';
    $args['render_callback'] = 'my_render_callback';
    
    return $args;
    
}

Disable the module

This module is enabled by default. To disable it, you can use the following code:

add_action('acf/init', 'my_acfe_modules');
function my_acfe_modules(){

    // Disable Dynamic Block Types
    acfe_update_setting('modules/dynamic_block_types', false);
    
    // Or:
    acf_update_setting('acfe/modules/dynamic_block_types', false);
    
}