Home › Forums › Gutenberg › Register Block Parent Attribute › Reply To: Register Block Parent Attribute
In case anyone else is looking for an answer, I found a solution…
Use block filters.
The blocks.registerBlockType
filter lets you modify block settings. So, I just added a parent setting with the block I wanted as a parent. Since the parent prop takes an array of blocks, more than one parent can be named.
/**
* Set ACF block parent
* @param {obj} settings
* @param {string} name
*/
function setBlockParent( settings, name ) {
if ( name !== 'acf/post-content' ) {
return settings;
}
return lodash.assign({}, settings, {
parent: [
'namespace/featured-content',
]
} );
}
addFilter(
'blocks.registerBlockType',
'namespace/set-post-content-parent',
setBlockParent
);
Hope it helps anyone else.
ref: https://developer.wordpress.org/block-editor/developers/filters/block-filters/#filters
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.