It seems this is happing because you’re switching between “Code Editor” and “Visual Editor” modes. Most systems will find it hard to maintain 100% code fidelity when switching between modes like this.
I’m wondering, does using the CUSTOM HTML BLOCK not suffice for your needs? That should avoid the problem you’re encountering altogether.
I’m also wondering… are you using empty hyperlink code like <a id="foo">text</a> to be able to create HTML anchor points? The block editor has a way to do this visually, no need to write custom HTML with an id like this to create anchors.
Thread Starter
QF0
(@qf0wp)
On this site, when one of these links is clicked, another part of the CSS grid on the same page is filled with relevant content. There’s CSS and JavaScript that handles the links, that highlights and increases the font size when hovering, that loads the new content, and so on, so it’s not really a traditional ‘link’. The CSS and JS does all this by matching on id. Maybe there’s a plugin that does all this, but I can never find a usable, supported, and high quality plugin when I need one, and it’s not a big deal to write the CSS and JS (no php required). However, it does rely on WordPress not messing with the HTML.
Never tried the ‘Custom HTML block’ thing. But if the problem is happening when the visual editor starts up, as you’re suggesting (and it sounds very plausible) I suspect this wouldn’t make any difference. It looks to me like it “checks” the page on startup, removes whitespace, and “fixes” the HTML without either understanding HTML or understanding that it might be there for a reason. Even something as simple as WS can be important – I put in lots of WS to line up tags in a long list, and something just removes it.
Looks like I’ll have to live with it for the next 10 years as well.