Why blocks.getSaveElement is not working for the core/social-link
? Is it because it is child of the core/social-links
?
When I modify example from the https://developer.wordpress.org/block-editor/reference-guides/filters/block-filters/, and replace core/cover
with the core/social-link
, it doesn't do anything:
function wrapCoverBlockInContainer( element, blockType, attributes ) {
// skip if element is undefined
if ( ! element ) {
return;
}
// only apply to cover blocks
if ( blockType.name !== 'core/social-link' ) { // replaced core/cover with core/social-link
return element;
}
// return the element wrapped in a div
return <div className="cover-block-wrapper">{ element }</div>;
}
wp.hooks.addFilter(
'blocks.getSaveElement',
'my-plugin/wrap-cover-block-in-container',
wrapCoverBlockInContainer
);
core/social-link
block is rendered in PHP then it doesn't matter what the save component generates it'll be ignored and PHP will be used. There's also a very high chance that you should not be doing this in the first place and there is a better way to do it, but without knowing why you want to do this it's hard to suggest the correct alternative. Generally what the code is trying to do is not good practice