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

I have a hook that adds additional data attributes to some of my allowed blocks. The problem is that the data attributes are not showing on the frontend for the post-title block. Everything is fine in editor but not on save function. I think this hook will not work for save dynamically created function. How can I pass these attributes to my accepted blocks, similar to 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

Leave a Comment