All I want to do is override a core block’s save function to render the frontend with different html. When I was on WordPress 5.3 I was able to override and make it a dynamic block (which I prefer) with php:
register_block_type( 'core/file', array(
'render_callback' => 'custom_core_block_render_cb',));
But now I’ve updated to WordPress 5.6 there’s a WordPress notice saying "WP_Block_Type_Registry::register was called incorrectly. Block type "core/file" is already registered."
Is this notice important enough for me to not ignore it? If no, then is there a way to get around it without resorting to overriding the save() on the javascript side with blocks.registerBlockType
since all it does it bring future problems and break the block in the future if I need to make updates (this really urks me). Also would rather not copy the entire block.
2
Answers
You shouldn’t be trying to re-register a core block. WP core blocks have a filter to change the output:
render_block
Here’s the filter:
apply_filters( 'render_block', string $block_content, array $block )
Here’s the usage:
Here’s the documentation:
https://developer.wordpress.org/reference/hooks/render_block/
Better solution for WordPress 5.5 – change only
render_callback