Posting Source Code in WordPress Posts

As a blogger that regularly posts source code, I really feel like I should’ve known about this a long time ago. I JUST learned that has built-in support for code formatting, and I really couldn’t be happier. My theme selection criteria was largely based on how well code would be displayed, and now I don’t need to be limited by that — hooray!

Here’s the post with all the juicy details:

[sourcecode language="<language>"]
your code here
    // I am SO excited about this!

And here’s the quick & dirty:

  • Replace <language> with the desired language to enable color-formatting (e.g., css, csharp, xml)
  • If a language is not provided, “text” will be used
  • Other options, like line-highlighting and line-wrapping can be controlled by optional attributes (highlight=”1,2″, wraplines=”true/false”)
  • Code will be automatically encoded for display — no more finding/replacing <‘s and >’s!
%d bloggers like this: