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.