Home › Forums › General Issues › Block.json default attributes › Reply To: Block.json default attributes
Yes, assigning defaults via block.json under attributes, as the WordPress documentation describes, is not reliable at all.
I really wish ACF would do more to explain what is supported and what isn’t.
I have resorted to using block variations to assign default attributes to my ACF blocks, because specifying them in block.json is useless:
wp.domReady(function () {
// USE BLOCK VARIATIONS TO ASSIGN DEFAULTS TO ACF BLOCKS
wp.blocks.registerBlockVariation(
'acf/map', [{
isDefault: true,
attributes: {
style: {
dimensions: {
minHeight: '450px',
},
},
}
}]
);
});
I place this in a .js file, then add this to functions:
add_action('enqueue_block_editor_assets', 'block_modifications');
function block_modifications()
{
wp_enqueue_script('block-modifications', get_template_directory_uri() . '/assets/js/block-modifications.js', array(
'wp-blocks',
'wp-dom-ready',
'wp-edit-post'
), filemtime(get_template_directory() . '/assets/js/block-modifications.js'), true);
}
There is probably a less hacky way of doing this. It would be so much simpler if we could just set the defaults inside the block’s json file in the way the official WP docs describe.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.