Wordpress is a pretty neat blogging platform, but it falls over quite spectacularly when trying to write code in posts. I write a lot of code for #! code and so I have understand what needs to be encoded to make code examples work.
For code example on #! code I use the code tag and I encode the following characters.
< into &lt;
> into &gt;
" into &quot;
' into &#39;
Note: You must be in HTML mode in your Wordpress editor or everything will be double encoded.