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?

  • Why do you need this?
    – Tom J Nowell
    Commented Oct 5, 2012 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. Commented Oct 5, 2012 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... Commented Oct 5, 2012 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
    Commented Oct 5, 2012 at 16:23
  • Try looking into shortcodes of the form [shortcode]content here[/shortcode]
    – Tom J Nowell
    Commented Oct 5, 2012 at 16:30

1 Answer 1


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]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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