WordPress – How do I post source code?

3 Sep

We have a shortcode you can wrap around source code that preserves its formatting and even provides syntax highlighting for certain languages, like so:

view plaincopy to clipboardprint

  1. #button {  
  2. font-weightbold;  
  3. border2px solid #fff;  
  4. }  
#button { font-weight: bold; border: 2px solid #fff; }

Wrap your code in these tags: [sourcecode language=”css”]…[/sourcecode]. You can replace the language with “css” with the language that you’re writing in. Currently we support syntax highlighting for the following language codes:

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

Code in between the [sourcecode] tags will automatically be encoded for display, you don’t need to worry about HTML entities or anything.

We used the syntaxhighlighter Google Code project by Alex Gorbatchev to implement this feature.

source : http://faq.wordpress.com/2007/09/03/how-do-i-post-source-code/


One Response to “WordPress – How do I post source code?”

  1. test March 22, 2010 at 9:49 pm #

    class Mate
    public static void Main()
    for(int i = 0; i < 10; ++i)
    Console.WriteLine("Hello {0}", i);

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 )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: