Hello,
The block shortcode was implemented in response to a user request. The reasoning was that when you use HTML in the text editor and then switch to Visual mode, you cannot see the HTML tags like <div> and <a> — making them easy to be accidentally deleted. So, by using block shortcodes, the HTML tags are visible and “protected”.
The extra <br> tags are caused by automatic formatting of post content. You can enable and use the [raw] shortcode to prevent this. That’s a good point, I’ll include a note in the documentation for HTML blocks.
To be honest, I haven’t used this feature much except for testing that it works. Usually I put most HTML and shortcodes outside the post, and leave the visual editor for content only.
Thread Starter
draig
(@draig)
Thanks for the explanation. That is clearer now… I had assumed that since Block was making it visible in the Visual Editor, that it was also protecting it too…
The automatic formatting is useful for text, but doesn’t work well with multi-line shortcodes and not easy to get around. So far, the best solution I found is to use [raw] or pull the shortcodes from outside the editor, as described in the Get Started page of the reference.
But, your comment made me think. Maybe it makes sense to strip <p> and <br> tags (usually added by auto-format) from inside the block shortcodes by default. In that case, it would be necessary to add them manually with [p] and [br]. Hmm..but that would change its default behavior and could have unexpected results with existing code.. I’ll have to think about it some more.