Set Core Block Attributes in Innerblocks template via PHP
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It only takes a minute to sign up.
Anybody can ask a question
Anybody can answer
The best answers are voted up and rise to the top
Asked
Viewed
3 times
I am hoping to make a custom <Innerblocks />
template for my custom block using some of the core blocks. The structure is meant to be:
Columns
Column
Heading
Paragraph
Button
Column
Image
Everything I have below is working so far barring two parts:
-
The columns
verticalAlignment
attribute is not being set. I am not sure which string arguments it accepts or if I am putting it in the wrong place. -
The button
backgroundColor
andtextColor
attributes are not being set. Again, not sure if I am placing this in the wrong spot of the array or if I should define these differently.$template = array( array( 'core/columns', array('verticalAlignment' => 'alignMiddle'), array( array( 'core/column', array(), array( array('core/heading', array( 'level' => 2, 'content' => 'Title Goes Here', )), array( 'core/paragraph', array( 'content' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.' )), array('core/button', array( 'text' => 'Learn More', 'backgroundColor' => '#00aeed', 'textColor' => '#ffffff' )) )), array( 'core/column', array(), array( array( 'core/image', array() ), )), )) );
Then I render it in my template file like so:
<InnerBlocks template="<?php echo esc_attr(wp_json_encode($template)); ?>" />
Should I be putting the attributes elsewhere within the array? What am I doing wrong?
1
lang-php
Leave an answer