Getting source code to display correctly in your blog can be a pain. I tried and tried to work with the <code> tags, but occasionally the visible code wasn't ok (for example replacing quotes and doublequotes incorrectly), taking one "-" off from html comment etc. Jumping on and off from "Visual" and "HTML" editor and updating a post seems to do this.
But of course there's a solution in the wonderful open source community and WordPress plugins that utilize the power. This isn't exactly breaking news as these have been around for while, as I picked up this post:
- WordPress Support: Writing & Editing Code. At that time, Alex Gorbatchev’s SyntaxHighlighter Google Code project was used to implement the source code highlighting feature.
I checked if this would've worked by default on self-hosted WordPress, but it seemed like it wouldn't, so I went to plugin hunt. And there seemed to be aplenty of plugins for source code publishing, some with syntax highlighting, some just making sure code displays correctly in <code> tag.
But this is what I decided to try for now and it seems to work nicely:
So whether you want to display just some html code or more advanced source code, these kind of plugins are for you. They are good for both one-two liners as they are for hundreds of lines of serious code. There's plenty of tags in use and all you have to do is enclose the code in a tag and define a language if you want. And the plugin supports a "lighter" style with no highlighting, but securing the formatting the same way.
Thanks for all these great blogs and bloggers for helping me by providing a bunch of information on the subject:
- WordPress Plugins That Help You Write Code @Lorelle on WordPress
- Writing Code in Your Posts - WordPress Codex
- Posting Source Code @WordPress.com Blog
- Writing and Publishing Code in Your WordPress Blog Posts @The Blog Herald
- Displaying Code In WordPress Posts @ThemeLab
So if you like to read more about source code in posts, check the above for detailed info.