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 WordPress.com 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: http://en.support.wordpress.com/code/posting-source-code/

[sourcecode language="<language>"]
your code here
[/sourcecode]
    // 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!
Advertisements

Leave a comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s