Replace duplicate block attributes in the Block Editor

Published: Leave a comment

Sometimes, you need to store unique data to a block to identify it later on. So you need to prevent having duplicate block attributes. In my case, I want to store a unique block ID. For this the clientId is useful as it’s already unique per definition (it’s a universally unique identifier generated on every editor load for every block).

Continue reading Replace duplicate block attributes in the Block Editor

wp_enqueue_block_style equivalent for scripts

Published: Leave a comment

Since WordPress 5.9, there is the new function wp_enqueue_block_style to enqueue block styles only if necessary, which means only if the associated block is rendered on the current page. While this is a huge benefit, there is no support for scripts. So if your block requires certain JavaScript only for the frontend, there’s no ready-to-use function within WordPress.

Continue reading wp_enqueue_block_style equivalent for scripts

Transform rgb()/rgba() to hex via PHP

Published: Leave a comment

While adjusting color values in PHP, I searched for a way to transform rgb() and rgba() to its hex code equivalents since I like those more. And since the hex notation in CSS allows defining an alpha channel for this since quite some time, there’s no showstopper to build a solution for this. But since this alpha channel notation is relatively new, I couldn’t find any code snippet in the wild that does what I like to. So I wrote it myself.

Continue reading Transform rgb()/rgba() to hex via PHP