How to Comment Out HTML Code in WordPress Posts and Pages

by Michael on July 12, 2013 · 3 comments

The other day, I had to remove a bit of content in a WordPress post. It was related to an affiliate offer that had expired but I wanted to save the relevant text/code in case they brought the offer back. I thus decided to comment it out.


Sadly, it didn’t work right. This is what I tried to do:

<!-- RandomChunkOfTextIncludingHTML -->

The HTML comment tags (<!-- and -->) should have been enough to comment out the stuff in the middle, but that didn’t happen. Instead, it screwed up the layout of the rest of the page.

Why? Apparently because it couldn’t handle nested HTML tags. But I found a workaround. Instead of the above, I used:

<!-- RandomChunkOfTextIncludingHTML <!-- -->

In other words, I used an opening comment tag, and the comment with an opening and closing comment tag. Boom. Done. For the record, the same thing works on WordPress pages, too.


{ 3 comments… read them below or add one }

The Bitemaster July 10, 2015 at 3:20 am

Thanks for solving the HTML-comment-in-Wordpress problem!

Reply

new year 2017 3d photos November 7, 2016 at 10:05 pm

Everything is very open with a really clear clarification of
the challenges. It was truly informative. Your site is very helpful.
Thank you for sharing!

Reply

sammenligne-kosttilskud.com December 10, 2016 at 1:10 am

Having a healthy and lively way of life can positively have
an effect on your profession in a good way.

Reply

Leave a Comment

Previous post:

Next post: