Commenting out HTML in a WordPress post or page

Using the built-in Text editor (as opposed to the Visual editor), it’s possible to directly add HTML code to any WordPress post or page. Unfortunately, WordPress doesn’t know how to handle HTML comments correctly. I often find myself wanting to hide HTML code without having to delete it, so these comments are pretty critical.

Here’s what a regular HTML comment looks like:

Here is some regular text, with a link.
1
2
3
4
<!-- Here is a comment that I don't want the browser to render. 
A second comment line. -->
 
<a href="link.html">Here's a regular HTML link.</a>

This will not render properly when entered into the WordPress Text editor. HTML comments do work in WordPress if you modify them this way:

Here is some regular text, with a link.
1
2
3
4
<!-- Here is a comment that I don't want the browser to render.
A second comment line. <!-- -->
 
<a href="link.html">Here's a regular HTML link.</a>

Happy commenting!

This entry was posted in wordpress. Bookmark the permalink. Both comments and trackbacks are currently closed.
  • Categories

  • Archives