• 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?

Viewing 15 replies - 1 through 15 (of 18 total)
  • Thread Starter Jason Spatola

    (@jasonspatola)

    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');

    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…

    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

    “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.

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

    Now what?! ??

    Anyone?

    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!!

    I found a plugin that seems to do the trick:

    Enable RAW HTML – Disable Corruption

    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…

    Thread Starter Jason Spatola

    (@jasonspatola)

    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?

    No problem.

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

    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.

    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.

    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.

    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?

Viewing 15 replies - 1 through 15 (of 18 total)
  • The topic ‘Visual Editor now strips HTML comments (new in 3.2)… How to prevent?’ is closed to new replies.