WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

There is a certain section of HTML that I need to comment out within the HTML editor in Wordpress. But when I do so, it breaks the HTML. After looking at the source code, I noticed that it converts the ending comment of this:


To this:


Anyone know how to go about commenting out HTML code within the editor without it converting it to that character?

share|improve this question
Why do you need this? – Tom J Nowell Oct 5 '12 at 15:58
I need to remove a div but it's going to be added back in later. Meh...you know what, I'll just do it with CSS. – ultraloveninja Oct 5 '12 at 16:05
However, it would be nice to know (for the rest of the community) why it changes that and if there is any way around it... – ultraloveninja Oct 5 '12 at 16:10
Because TinyMCE only allows a subset of tags for security reasons. You shouldn't need to include div tags in content anyway, content is for content, layout belongs in the theme templates and stylesheets – Tom J Nowell Oct 5 '12 at 16:23
Gotcha. Thanks for your input! – ultraloveninja Oct 5 '12 at 16:29

My last comment reminded me about shortcodes, and lead me to this answer:

function htmlcomment_shortcode( $atts, $content = null ) {
   return '<!-- ' . $content . ' -->';
add_shortcode( 'htmlcomment', 'htmlcomment_shortcode' );

Add that to functions.php or your plugin, and then use it in your content like this:

normal text [htmlcomment]commented out text[/htmlcomment]

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.