Comment out code in HTML view

  1. Michael Madison

    Although you can use "<!-- Some comment -->" to document HTML, you can't use commenting reliably to hide code that includes tags.

    Standard HTML "comment out" functionality is useful when temporarily deactivating code that may be needed later.

    I think there's a workaround, but it shouldn't be necessary.

    Posted: 2 years ago #
  2. Ipstenu (Mika Epstein)

    You shouldn't be using it in posts or comments, though. There's no reason for it.

    Posted: 2 years ago #
  3. Thanks for your reply. I agree that it wouldn't be needed for comments; however, I think there's are powerful reasons for it in posts.

    The problem seems to be that WordPress gets "confused" about where "<!--" is ended. I believe everything between that opening comment tag and the closing "-->" should be ignored.

    In my case, I have many elements on both pages and posts that I sometimes use and sometimes don't. Commenting out HTML code is common practice for some. People using WordPress for its original blogging strength, rather than as a CMS, are probably less likely to be bothered by this.

    Whether this behavior is changed or not will never dim my enthusiasm for WordPress. It ranks among the best choices I've ever made in anything. I'm just passing this along as a suggestion.

    Just to make this clearer: I never use the visual editor at all. It's not even a visible option.

    Posted: 2 years ago #
  4. Ipstenu (Mika Epstein)

    Given that there was recently an exploit revealed by people using mfunc php calls within comments, I would actually see this being stripped :/

    However I feel like I should point out that you're not supposed to be putting a lot of HTML elements in your post content :) Non-Admins can't, for one. Non super-admins can't on a multisite.

    Posted: 2 years ago #
  5. I understand your points and they are valid. And I agree that using HTML in posts is dangerous, if many people are adding to the site.

    But my site doesn't have editors or outside contributors. And I'm guessing there are others like me in that regard.

    Posts and pages are major means of showcasing elaborate content. Calls to PHP are another. In any case, since there is an HTML editor, I can state that -- for me -- being able to comment out code temporarily and leaving it for possible future use is a feature I would like.

    Still, I can see where you're coming from. My main point is that, whether commenting out code (or even adding HTML elements) is good or bad, it is permitted. So, the ability to occasionally comment it out, as is common practice in other environments, would be useful. I can work around it by saving code and reinserting or, in some cases, by simply switching to "display: none;" from "display: inline;".

    So, on reflection, if this doesn't seem like a good feature to WordPress developers or if it is considered outside the community intent, then there are more important things to focus on, and I withdraw my request. Thanks for considering this.

    Posted: 2 years ago #
  6. i think there is a good reason to have hidden text in posts as an option maybe the html comment out code isn't the way (although I'm not sure what would be if that wasn't) for instance if you plan on having revisions to a page or have parts of the page/post which are only applicable in certain date ranges but you don't want to have to erase and then re-type the content a comment out functionality would be quite useful.

    just saying…


    Posted: 9 months ago #
  7. byronyasgur

    In my case I want to have a block of code that will be left out of the display occasionally. That's a good reason to have the comment ability. just my 2c.

    Posted: 8 months ago #
  8. Cyberchicken

    I support Michael Madison statements.

    We web developers more often than not just want a text editor to write our code; we don't want any software to kick in automatically and filter or validate anything. We trust ourselves and take our responsibility.
    It's a request of comprension to the core developers: I know it's hard task, but you have to strive to satisfy BOTH the untechie user (who made great wordpress till now) AND the war-weary web developer (who's endorsing wordpress as great platform for almost everything).

    Personally I'd always liked the idea to have two different HTML editors, one for the technicians and one for the writing people.
    Currently this is not possible because of the position of the hooks of wpautop, wptexturize and other filters.

    If WordPress Core wants to support common users with writing assistance I agree and that's more than fine with me, but those aids should be written in the the db (for me to edit them afterwards), and must be of medium-high quality (eg beautified comments-and-whitespace-preserved html).
    As for now it's an all-or-nothing situation: I always have to turn off filters and reconfigure TinyMCE to edit HTML decently, but then it's for all users, not just for me.

    Thak you for discussing this.

    Posted: 1 month ago #

RSS feed for this topic


You must log in to post.

  • Rating

    0 Votes
  • Status

    Sorry, not right now