WordPress.org

Ready to get started?Download WordPress

Forums

Visual Editor now strips HTML comments (new in 3.2)... How to prevent? (19 posts)

  1. Jason Spatola
    Member
    Posted 3 years ago #

    In previous versions, adding advanced markup in WordPress posts was easy - adding an HTML comment to a div would prevent the editor from stripping it, as in:

    <div class="clearleft"><!----></div>

    Just an example of how something like that could be useful - a functional, empty div.

    Old versions would leave these elements untouched.

    In 3.2, however, switching from the HTML editor to the wysiwyg editor removes these entirely.

    Is there a way to restore the old behavior/prevent this from happening?

  2. Jason Spatola
    Member
    Posted 3 years ago #

    Can't really figure out what specifically changed and led to this problem, but turning off element cleanup saves the day.

    Add to functions.php:

    function mod_mce($initArray) {
    	$initArray['verify_html'] = false;
    	return $initArray;
    }
    add_filter('tiny_mce_before_init', 'mod_mce');
  3. sarumbear
    Member
    Posted 3 years ago #

    I am not a full-fledged WP developer by any stretch of the imagination and I am sure there is a valid reason why the Visual Editor is stripping valid HTML code BUT: It is downright stupid!

    There is a reason why the HTML editor exists, yes? To allow you insert code that the Visual Editor cannot. Then why on earth it deletes the code you placed there? It just does not make sense at all!

    The code stripping functions has no place in Visual Editor and should be removed. For whatever the reason that facility exists, another means should be found.

    Logic should prevail...

  4. Tim Wright
    Member
    Posted 3 years ago #

    I'm all for removing [style] and [script] (so clients don't do anything terrible), but removing html comments doesn't seem like it gets you anything

  5. sarumbear
    Member
    Posted 3 years ago #

    "I'm all for removing [style] and [script] (so clients don't do anything terrible)"

    How can a client do something terrible with style???

    Besides, if you stay on the HTML view you can do and publish anything and everything rill your heart is contend and do terrible things to your site or other sites for that matter. You are not stopping anything. You are just inconveniencing the people who needs the HTML editor, which you admitted they do by making it available in the first place.

    Not logical for a self hosted installation.

  6. DoZ
    Member
    Posted 2 years ago #

    For me is still a problem, not solved by adding that code to functions.php! :(

  7. luchomolina
    Member
    Posted 2 years ago #

    Now what?! :(

    Anyone?

  8. DoZ
    Member
    Posted 2 years ago #

    ok, I was quasi wrong!

    It works sometimes!
    IE:

    <!--more--><!--xxx-->
    <!--xxx-->

    First line lives, second line dies!
    Don't know why!

    But that's not all!

    After that test I tested without the new function, and do you know what?
    It works the same way! With any new functions!!

  9. jrhall
    Member
    Posted 2 years ago #

    I found a plugin that seems to do the trick:

    Enable RAW HTML - Disable Corruption

  10. Quin
    Member
    Posted 2 years ago #

    The odd thing is that I have a similar problem (and nothing else works).

    Visual takes it all away, HTML keeps it as it is (for me).
    Another Admin edits the post, and it gets stripped (even though the page is edited in HTML view).

    This is the first time I've ever come across this. Is there a way to add custom style in the Kitchen Sink so text can be wrapped in specific styles? (maybe a solution?)

    EDIT: I added the code to the function page, but it didn't solve anything.
    However, for me, I simply stopped using id and didn't use numbers for class names.

    I wonder what will happen if I remove the code from function.php...

  11. Jason Spatola
    Member
    Posted 2 years ago #

    The HTML comments weren't totally vital to me - I used to use them as "placeholders" to keep empty divs from being gobbled up.

    To that extent, I found a better way of doing this... To simply keep all divs, empty or not, I use this function:

    function my_tinymce( $init ) {
    	$ext = 'div[id|name|class|style]';
    
    	if ( isset( $init['extended_valid_elements'] ) ) {
    		$init['extended_valid_elements'] .= ',' . $ext;
    	} else {
    		$init['extended_valid_elements'] = $ext;
    	}
        return $init;
    }
    add_filter( 'tiny_mce_before_init', 'my_tinymce' );

    Also, jrhall - thanks for the heads up. Have you/anyone tested this to see if HTML comments are preserved?

  12. jrhall
    Member
    Posted 2 years ago #

    No problem.

    Are you referring to HTML comment code
    <!-- comment -->
    Or HTML in post comments?

  13. jrhall
    Member
    Posted 2 years ago #

    Okay. New info for comment woes:

    The plugin I posted isn't completely effective, as it turns out. It will prevent comments from being fouled up in the editor, and those changes from being reflected in the editor, but it won't fix the page output.

    WordPress is still slapping <p> on comments. If I post a single line comment:
    <!-- some comment -->
    When I view the HTML source, it becomes:
    <p><!-- some comment --></p>

    It's not a huge deal, except for when you want to do a multi-line comment.

    In that case, your comment:

    <!-- Line one
    and two
    and three -->

    Winds up:

    <p><!-- Line one </p>
    and two
    <p>and three & #8211;></p>

    Then any subsequent comments you try to make are completely obliterated. You'll get the initial <!-- but then your closes all become & #8211;></p>, and your whole content area goes to pieces.

  14. jrhall
    Member
    Posted 2 years ago #

    Found a solution to my issue - may be helpful to others.

    The plugin I suggested does actually work.

    The problem is actually that another plugin will prevent that plugin, and any other manual code insertions to remove the wpautop filter, from taking effect. It turns out that, for me, the Shortcodes Ultimate plugin was the culprit. Once I disabled that plugin, the Enable Raw HTML plugin fixed the issue.

    Hope this helps someone else.

  15. emidi
    Member
    Posted 2 years ago #

    sarumbear, I totally agree the visual editor making changes to the HTML is bloody annoying!

    jrhall, thanks for the link but the plugin is not working for me. At first I thought maybe it is just a problem with the theme I am using but I have tested it on a another theme with all the other pluggins disabled and it still does not stop the visual editor from changing the code.
    Any suggestions?
    Thanks in advance.

  16. emidi
    Member
    Posted 2 years ago #

    I have tried adding

    function mod_mce($initArray) {
    $initArray['verify_html'] = false;
    return $initArray;
    }
    add_filter('tiny_mce_before_init', 'mod_mce');

    to the functions.php file, but that does not stop it either.

    Anyone with some good advice?

  17. a4jp.com
    Member
    Posted 2 years ago #

    I was just adding Microdata to my contact page and wanted to look at it visually so I clicked on that evil button as well. All the useful code I just typed in got stripped away :( boo

    There should be an option to turn off that feature. How do we add image maps or Microdata if the code gets stripped away?

  18. sarumbear
    Member
    Posted 2 years ago #

    I gave up and started to use the RAWR plugin. It allows you to place code within [rawr]...[/rawr] shortcodes and works like a charm.

  19. You can add image maps with Ultimate Tinymce (however you must use firefox when creating the image map).

    http://wordpress.org/extend/plugins/ultimate-tinymce/

Topic Closed

This topic has been closed to new replies.

About this Topic