Posting source code on a WordPress hosted blog

Published 04 May 2012

As you probably have noticed, this is a code-oriented blog. Sicne I post a lot of code, I have been annoyed for a long time, that the code has been terribly formatted.

The reason for this is that wordpress.com has some limitations when it comes to themes and plugins. Since I have not yet found a good way to handle code here, I have wrapped the code in pre tags and highlighted it with a distinct color, but the result has been mediocre.

A couple of weeks ago, however, I found this blog post by the WordPress team. It turns out that posting source code and getting it to format correctly is a walk in the park, using the sourcecode markup, as such:

[code language=”css”] your code here [/code]

Use this markup, and WordPress will format the source code correctly. It supports many different languages, e.g. C#, Java, JavaScript, CSS, XML etc. Have a look at this blog post for examples.

Thanks, WordPress!