Add an unique class to every wp block on save

Viewed 178

How can I add a unique class name to every gutenberg block on save? I tried doing this with php using a combination of wp_after_insert_post, parse_blocks, wp_update_post and something like (simplified):

$block['attrs']['className'] = $block['attrs']['className'] .' ' . substr(md5(uniqid(rand(1,6))), 0, 8);

But even though the classes are saved in the db, they don't show in neither the front end or the block editor.

enter image description here

0 Answers
Related