HTML comments in Gutenberg
-
I have searched for this but haven’t found an answer.
I am using Gutenberg and after a slow learning curve, I now like it. But I can’t comment out text.
In the old days, if I had text I wanted to modify but it wasn’t finished, I could put an HTML comment tag at the start and a closing tag at the end and all the text didn’t show to visitors.
But now, I don’t seem to be able to comment out, even though I have tried small sections or whole HTML blocks.
Is there a solution please?
The blog I need help with is: (visible only to logged in users)
-
Thanks for writing to us. I’m happy to take a closer look. Can you point me to the post/page where you’ve been working on this html? Also, add the comment tag here in
code ticksso it doesn’t get stripped out. -
Hi, thanks for the prompt response.
There is no use in pointing you to the page because as a temporary measure, I have cut out the text I am still working on and saved it on my desktop, so there is nothing there to see.
I was using the standard HTML comment tags,
<!----at the start and--->at the end, which on an old HTML page would work. I tried using these tags in a small part of the text (i.e. within a paragraph block) and also in separate Custom HTML blocks before and after the text, but in both cases the tags just appeared as text. -
-
Alright. The comment tags aren’t going to work in the paragraph block. But, when using the html block they work as expected.
<!--comment tags-->We added a testing page (draft) to the site so you could see it there.
-
Thanks again for your help, I really appreciate it.
Yes, I was using the Custom HTML block.
And, yes, I can see how the single comment appears. But I was trying to comment out a whole block, or several blocks, of text, and that doesn’t seem to work. I have reproduced this on the test page now, and you can see that the comment tags appear as text instead of working as tags.
(You can also see they are way over to the left edge of the screen. This hasn’t been the only think that has appeared like this for me – the “More” tag was doing the same. I have had some discussion on a different thread, where the designers resolved that one, but maybe this has the same cause.)
Thanks again.
-
I can’t seem to duplicate this on my test sites either. Here’s what I see:
I do see something odd on your site though.
Can you try just using two dashes after the beginning of your comments tag, and only two dashes near the end?
-
I’ve tried using two dashes, but there’s no difference.
I think your trial page is doing something different. My problem is commenting out several whole blocks of text, not just some text within a block (though I had trouble doing that as well – I think it has to be in a HTML block rather than a paragraph block, as lizkarkoski said). This is a common way to debug a problem – comment out some text rather than actually remove it to see if the problem persists.
It isn’t a crucial issue because I can always just remove the text and save it elsewhere until I can sort it, but HTML used to work this way, so it would be good if Gutenberg could work this way. But perhaps there’s some fundamental reason why it can’t be done, in which case we just get used to doing things a different way.
Thanks.
-
My problem is commenting out several whole blocks of text, not just some text within a block
That is not possible.
Each block of content in the block editor is a unique section of content within the document as a whole. Any formatting (or in this case, HTML comments) you apply to content in a particular block, will only apply to content in that specific block.
What you want is to essentially comment out entire blocks, but that would require you to comment out the markup that create the blocks themselves, by adding the opening and closing tags for your comments outside of the block markup itself, using the Code Editor view. But the block editor was not designed to ever contain content that’s not inside a block, so this also won’t work.
In this case it’s not something that can be fixed, as nothing is broken – this is simply not how the block editor was designed to work.
By the way, HTML comments do work in the paragraph block, but you have to edit the paragraph block as HTML – click the … on the block toolbar, select Edit as HTML, and add the comment tags. Then click … again and select Edit Visually, and the text will no longer be visible. You don’t need a HTML block to do this.
-
OK, thanks for that explanation. This is a mildly unfortunate feature of having a block editor. I can live with that now I know. Thanks for going to the trouble of explaining it to me.
- The topic ‘HTML comments in Gutenberg’ is closed to new replies.