Home Forums Gutenberg Adding ACF blocks to a block template


Adding ACF blocks to a block template

  • Hiya

    I have been following the code examples on:

    To be able to add additional blocks to forma block template. Is there any way to integrate an ACF block into these templates?

    My code so far is:

    function my_add_template_to_posts() {
    	$post_type_object = get_post_type_object( 'page' );
    	$post_type_object->template = array(
    		array( 'core/paragraph', array(
    			'placeholder' => 'Add a root-level paragraph',
    		) ),
    		array( 'core/columns', array(), array(
    			array( 'core/column', array(), array(
    				array( 'core/image', array() ),
    			) ),
    			array( 'core/column', array(), array(
    				array( 'core/paragraph', array(
    					'placeholder' => 'Add a inner paragraph'
    				) ),
    			) ),
    		) )
    	$post_type_object->template_lock = 'all';
    add_action( 'init', 'my_add_template_to_posts' );

    But not sure how to reference a pre made ACF block?

    Any help would be grateful



  • Hi Tom,

    I was expirimenting with the same thing as i couldnt find information about this.

    But for example:

    First You create a custom block via acf_register_block:

    	'name'              => 'blockname',
    	'title'             => __('title'),
    	'description'       => __('description')

    Then you can take the name of the acf_block ‘blockname’ and use it as following in your post type template:

    	$post_type_object->template = array(
    		array( 'acf/blockname', array() ),		

    Note: If your blockname contains a space or a underscore, acf renames this to a dash, so ‘block_name’ becomes ‘block-name’.

    Hope this helps!

    • kkoyan

    • February 5, 2020 at 2:07 am

    Taking this a bit further, is there a way to add default values in a template?

    In the wordpress documentation I see that you can add for some core blocks a placeholder.
    Is there a way to add default content in acf blocks when you define them in the block template?

  • I second kkoyan’s question. Adding Gutenberg template blocks where the ACF block contents are preselected would be appreciated.

  • @jagenda +1

    • jonk

    • May 11, 2020 at 11:02 pm


    I was expecting something like this to work, but computer says no …

    array( ‘acf/blockname’, array(
    ‘header’ => __( ‘You may also like’, ‘td’ ),
    ) ),

    where header is the name of the field.

    • ProxxiM

    • December 11, 2020 at 12:53 am


    It would be very nice to predefine values for blocks in templates.

  • +1

    It’d saves plenty of times, and give us the real power to use acf blocks as template

  • Hey Guys,

    This is possible already.

    Here is the post about it:

    And the code which helps you to make better experiences! : )
    The magic is that, you need to wrap them with a data []

    'template' => [
         ['acf/my-block', [
           'data' => [
            'field_name' => 'the value you want to see by default',

    I hope it helps you too as well!

    I’m stuck with repeater subfields now.
    Didn’t find a way to fill them yet.
    If any of you able to do that, don’t hesitate to write here about that. 😉


    • ProxxiM

    • January 8, 2021 at 9:01 pm

    Wow, thanks for the tip @chrisdark! 😄

    • deejmer

    • April 17, 2021 at 5:54 am

    Agreed, three cheers to @chrisdark for this. I searched high and low for this data[] tag to set my custom field values. I have to populated cloned field values…did you ever figure out how to tap into a subfield (which I suspect would use similar syntax)?

Viewing 11 posts - 1 through 11 (of 11 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.