Thursday, 7 March 2013

Websiting

Today I was just doing more website work. One very annoying problem I came across that I haven't found before was wordpress breaking an html comment e.g.

<!-- stuff to be commented out -->

Wordpress would automatically change the two dashes in the end comment markup to &#8211;. And of course, this meant that the end comment block was now no longer an end comment block, and so the rest of the page was commented out (disappeared).

You can read other people complaining about wordpress' behaviour here: Visual Editor now strips HTML comments (new in 3.2)... How to prevent? However, for me this was happening in the text editor, not the visual editor. It was also happening with the comment only on a single line (it was enclosing an img tag), there were no line breaks between the start and end blocks of the comment.

The solution was to remove the filter 'convert_chars' from 'the_content' in my theme's functions.php file. This does have the potential to cause problems down the line as the site will be edited by people using the visual editor. So I just hope that TinyMCE converts chars that are not allowed (e.g. &, ") into entities rather than relying on convert_chars to do it.

No comments: