Filter – How to add custom HTML attribute to reusable block div in wordpress admin?

So what I’m trying to clarify is when an editor is editing a reusable block in the wordpress admin.

For this, I need to add a custom attribute title printed in the div of the reusable block in the wordpress admin.

I’ve found that I can change it a bit with this code, but it’s just static and can’t connect it to each render block:

add_filter( 'block_type_metadata', function ( $metadata ) {
    if ( 'core/block' === $metadata['name'] ) {
        $metadata['title'] = 'Reusable Block Title Test';
    }
    return $metadata;
});

I can’t find a way to do something like this data-reusable-block-title="Product Slider for Global"(this is the title of the reusable block) in HTML as it is rendered via JavaScript.

how can i get the post title from the post id of the reusable block and then input it into the html attribute of the gutenberg block being rendered by javascript and then using that attribute in css to create that styling Can I do what I like?

I’m looking for a result of something like this without needing to re-save each page and somehow store it in block data and retrieve it like this:

Thanks in advance!

Leave a Comment