10 Tips for Writing Code in WordPress Posts
When you look at the WordPress default editor, you have two options: Visual or HTML. If you use the Visual editor, it will look at code as ordinary text so it will convert (encode) a < character into <. This will prevent the code from being interpreted by a web browser.
In contrast, if you use the HTML option, none of these characters are converted so if you use HTML and CSS (as an example), this code WILL be recognized by your browser and can cause real havoc with your layout.
Other factors are the version of WordPress, the post editor used, and the types of plug-ins you have on your system. Here are some solutions to the problem: