How to develop custom blocks without triggering validation errors

You have two choices.

The first one you’ve discovered: change the block’s underlying code, and you will trigger validation errors. The benefit is, you’re only including the JS currently required for your block – so it keeps the code as lightweight as possible.

The second option: add deprecated code into your block. In this case, you define not only the block as you want it to be now, but also past (deprecated) versions of the block, so WP recognizes the old and can transform it to the new version every time you edit a post. The benefit is, this won’t trigger validation errors (and potentially blank blocks) whenever you update the save() output. The downside is, the more times you change the output and keep the “deprecated” code available, the heavier your plugin gets.

Leave a Comment