How to post sourcecode to WordPress

28 02 2010

Ok, so maybe I did a post like this before with a less than stellar result. At least it was better than my new solutions where I paste images and raw black text into the posts. Hopefully, those days will now be gone. I’ve been digging around the WordPress resource section and realized that you can do quite a lot of things very easily. Pasting code seems like one of them. I’ll try this by just pasting some random C# and XAML.

coding silverlight maybe?

coding silverlight maybe?

XAML with the XML lang spec

<Button Name="myButton>
  Click me pleeeeease!!!
</Button>

XAML with the no lang spec

<Button Name="myButton>
  Click me pleeeeease!!!
</Button>

C#

if(true)
  {
    Button myButton = new Button();
    myButton.Text = "Click me pleeeeease!";
  }

Not a big difference between XML and plain text. I’d very much like to see a XAML option here. So, to post code properly like this, simply use this block in your html when creating a post:

[ + sourcecode + ] (without the + signs)

your code here

[ + /sourcecode + ]

If you want to use a specific language, write “language=csharp” in the first block, like this:
[ + sourcecode language=csharp + ]

So from now on, I’ll feature much nicer sourcecode whenever I post it. Everyone wins. Full list on the different language codes can be found here


Actions

Information

2 responses

7 10 2010
reportingavatar

Great post! Nice and crisp…

8 10 2010
Viktor Larsson

Thanks! This is actually one of the posts I most often return to myself :P It’s a good reminder.

Leave a reply to reportingavatar Cancel reply