The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My work

  • My badges

  • Twitter Updates

  • My Flickr Stream

    20140417-Windows-8.1-Update-says-it-failed-but-it-succeeded

    20140417-Windows-8.1-Update-says-it-failed-but-it-succeeded--Windows-Help-and-Support--cannot-find-any-info--how-surprising-it-never-does

    20140329-VMware-vSphere-Client-4.1-retry-with-compatibility-settings

    More Photos
  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,254 other followers

Including formatted sourcecode in WordPress

Posted by Jeroen Pluimers on 2009/04/22

Since I’m quite new to WordPress it is a learn as-I-go process (sounds familiar huh?) and a major goal of this blog is to keep track of things so that I don’t forget them:

Including formatted code in your blog is easy, WordPress has a FAQ about it!
Basically it comes down to adding the sourcecode shortcode and then make sure the language attribute has the right value.

But there are some gotcha’s that are not in the FAQ:

  1. paste the sourcecode shortcode as “plain text” (or in the HTML editor) otherwise it will get span tags around it and not render as code
  2. C# has language code csharp (if you use a non-existing language code, it will not render as code either)

The language codes I will probably use most are csharp and delphi, followed by xml and sql and maybe some css and html.

In your editor, you will then see something like this:

[sourcecode language='csharp']
using System;
namespace bo.hi
{
  class Program
  {
    static void Main(string[] args)
    {
      Console.WriteLine("Hello World!");
    }
  }
}
[/sourcecode]

which will then be rendered in your reader’s browser like this:

using System;
namespace bo.hi
{
  class Program
  {
    static void Main(string[] args)
    {
      Console.WriteLine("Hello World!");
    }
  }
}

And the list of valid language codes:

  • cpp
  • csharp
  • css
  • delphi
  • html
  • java
  • jscript
  • php
  • python
  • ruby
  • sql
  • vb
  • xml

8 Responses to “Including formatted sourcecode in WordPress”

  1. [...] Thanks to Joeren Plumier’s blog! [...]

  2. [...] another update t… on TFS 2008 Folder Comparison Fil…Posting source code … on Including formatted sourcecode…jpluimers on Commandlines for shutdown, reb…Bert Haver on Commandlines for shutdown, [...]

  3. [...] Comments jpluimers on C#/.NET – GetExecutableP…yet another update t… on Including formatted sourcecode…brad on C#/.NET – GetExecutableP…yet another update t… on TFS 2008 Folder [...]

  4. [...] This is a follow up on the original article Including formatted sourcecode in WordPress « The Wiert Corner – Jeroen Pluimers’ irregular str…. [...]

  5. [...] the past I wrote a few blog posts on posting sourcecode in [...]

  6. kristobaldude said

    Reblogged this on CodeSlayer2010 : Slaying Code 24/7!.

Leave a Reply

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

 
Follow

Get every new post delivered to your Inbox.

Join 1,254 other followers

%d bloggers like this: