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

Question

I have a hook that add extra data attributes to some of my allowed blocks. The problems is the data attributes are not showing on the frontend for post-title block. In the editor everything is fine but not on the save function. I’m assuming that this hooks will not work for save function that is created dynamically. How can I pass these attributes to my allowedblocks same as core/post-title

const addMarginPaddingDataAttributesToFrontEnd = (
    props,
    block,
    attributes
) => {
    if ( ! allowedBlocks.includes( block.name ) ) {
        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',
    'custom/save-data-attributes',
    addMarginPaddingDataAttributesToFrontEnd
);

enter image description here
enter image description here

0
tomtomczuk 3 weeks 2022-11-13T09:53:47-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse