Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
show 2 more comments

1 Answer

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
add comment

Your Answer

 
discard

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.