Is it at all possible to display HTML code in Wordpress?

OK, i figured out what to do.

  1. First go into visual mode.
  2. Select Preformatted in the formatting drop down. A little grey box is created.
  3. Inside the grey box, copy and paste your raw HTML.

Save it and switch from visual to HTML views a few times. There should be no mangling.

IT IS ABSOLUTELY CRUCIAL that you paste into visual tab, instead of in the text tab, or it will get stuffed up completely (very unintuitive. You would think it would work the other way araound).


Wordpress does a strange thing where if you switch between visual and "text" mode (HTML mode was renamed in 3.5 update) it strips any tags that appear empty which often times may not be. This might be what you are experiencing if I am understanding the problem correctly.

If you are just trying to display code on your website you should be able to wrap the code like this:

<code><p>Example code post</p></code>

This is laid out in these guidelines here: http://codex.wordpress.org/Writing_Code_in_Your_Posts

If it is a block of code that needs to not wrap you could also use the "pre" tag like so:

<pre><code><p>Example code post</p></code></pre>

This is described very well here: <code> vs <pre> vs <samp> for inline and block code snippets

Tags:

Html

Wordpress