Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is It Possible to Comment Out HTML Code in a Wordpress Post?

Tags:

Sometimes I need to inject some raw HTML code into a Wordpress post, and sometimes I need to comment out a chunk of that code.!

With a plain text editor, I can just use <!-- Comment --> around the chunk I want to hide.

But when I try this in a WP post, it does hide the code but I still see the "closing comment tag" -->.

What's the right way, if possible, to comment out code in a WP post?

Thanks!

like image 709
user249493 Avatar asked Jul 27 '10 13:07

user249493


People also ask

Can you comment out HTML?

This element is used to add a comment to an HTML document. An HTML comment begins with <! –– and the comment closes with ––> . HTML comments are visible to anyone that views the page source code, but are not rendered when the HTML document is rendered by a browser.

How do you comment an entire HTML code?

Comments in HTML start with <! -- and end with --> . Don't forget the exclamation mark at the start of the tag! But you don't need to add it at the end.

How do you comment off code?

The leading characters // are added to the beginning of each line when commenting one or more lines of code. You can also block comment multiple lines of code using the characters /* */ .


2 Answers

wpautop() contains a bug that breaks comments containing HTML code. An easy workaround is to add a second opening HTML comment tag just before the closing - this tricks WordPress into working like you would expect it to. see http://core.trac.wordpress.org/ticket/2691

This will work in WordPress:

<!-- <div class="book floatleft"><a href="#"> <img src="http://www.myreallycoolsite.com/wp-content/uploads/2013/02/button.png" alt="" /> </a></div> <!-- --> 

This will not work in WordPress:

<!-- <div class="book floatleft"><a href="#"> <img src="http://www.myreallycoolsite.com/wp-content/uploads/2013/02/button.png" alt="" /> </a></div> --> 
like image 74
jharrell Avatar answered Sep 21 '22 09:09

jharrell


Use a hidden div block

like this:

<div style="display: none;">  ...comment...  </div> 

works like a charm

like image 41
ecume des jours Avatar answered Sep 21 '22 09:09

ecume des jours