Sunday, November 13, 2022
HomeWordPress Developmentblock editor - getSaveContent.extraProps hook for core/post-title would not add new attributes...

block editor – getSaveContent.extraProps hook for core/post-title would not add new attributes on to the frontend


I’ve a hook that add further knowledge attributes to a few of my allowed blocks. The issues is the info attributes aren’t exhibiting on the frontend for post-title block. Within the editor every little thing is okay however not on the save perform. I am assuming that this hooks is not going to work for save perform that’s created dynamically. How can I go these attributes to my allowedblocks inc. core/post-title ?

const addMarginPaddingDataAttributesToFrontEnd = (
    props,
    block,
    attributes
) => {
    if ( ! allowedBlocks.consists of( block.title ) ) {
        return props;
    }

    const margins = prepareDataString( attributes.margins );
    const paddings = prepareDataString( attributes.paddings );

    const newAttributes = {};
    if ( margins !== '' ) {
        newAttributes[ 'data-margin' ] = margins;
    }

    if ( paddings !== '' ) {
        newAttributes[ 'data-padding' ] = paddings;
    }
    return assign( props, newAttributes );
};
addFilter(
    'blocks.getSaveContent.extraProps',
    'customized/save-data-attributes',
    addMarginPaddingDataAttributesToFrontEnd
);

enter image description here
enter image description here

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments