2

ACF has introduced inner block support which I'd like to use.

Via my block template, I have the following:

<?php
$allowed_blocks = array( 'core/heading', 'core/paragraph' );
echo '<InnerBlocks allowedBlocks="' . esc_attr( wp_json_encode( $allowed_blocks ) ) . '" />';

This limits the block editor to headings and paragraphs only.

Is it possible to add a class attribute to each heading and paragraph? For example, <p class="block__paragraph">.

I'm aware I can achieve this with str_replace but I wondered if there's a more efficient way to hook into InnerBlocks?

I'm also aware you can use templates, like so:

<?php
$template = array(
    // Heading
    array( 'core/heading', array(
        'level' => 2,
        'placeholder' => 'Add a Title',
        'className' => 'block__heading',
    ) ),
    // Paragrph
    array( 'core/paragraph', array(
        'className'    => 'block__paragraph',
        'placeholder'  => 'Write your text.',
    ) ),
);
echo '<InnerBlocks template="' . esc_attr( wp_json_encode( $template ) ) . '" templateLock="false" />';

However, this limits the editor to a set number of blocks.

Sam
  • 1,401
  • 3
  • 26
  • 53
  • I know it's not really much help but after some investigation I found these two articles that show some JSX usage and I think that could be key to resolving this: https://developer.wordpress.org/block-editor/how-to-guides/block-tutorial/nested-blocks-inner-blocks/ https://www.advancedcustomfields.com/resources/acf_register_block_type/#:~:text=Adding%20inner%20blocks%20%F0%9F%91%A9%E2%80%8D%F0%9F%91%A7%E2%80%8D%F0%9F%91%A6 – Justin Jul 27 '22 at 10:01

0 Answers0