Software Engineering

by Kerem Kosaner

Source Code in WordPress

Posted by keremkosaner on 12 November 2007

Blogs in WordPress can be created either in a subdomain of wordpress or with your own domain name. So there can be 2 scenarios. For the ones that are created under wordpress (subdomain of wordpress) syntax highlighting plugin is activated by default. So if you want java code to appear with syntax highlighting you need to include your java source code between the “sourcecode ” tags in “[]” like sourcecode language=”java” , sourcecode language=”csharp”, sourcecode language=”xml”. The other languages supported in the language attribute are: cpp, css, delphi, html, jscript, php, python, ruby, sql, vb

JAVA CODE:

//  HelloWorld.java
public class HelloWorld {
   public static void main (String args[]) {
      System.out.println ("Hello, World!");
   }
}

C# CODE:

// HelloWorld.cs
public class HelloWorld
{
   public static void Main()
   {
      System.Console.WriteLine("Hello, World!");
   }
}

XML CODE:

<test-test>
     <test-hello>world</test-hello>
</test-test>

This can be used for posts with different programming language source codes. In order to know more on the usage for different programming languages syntax highlighting in wordpress visit:

http://faq.wordpress.com/2007/09/03/how-do-i-post-source-code/
 
The approach works on http://www.wordpress.com , but it wont work on your own site which uses the wordpress platform. There is a solution for that also. You need to install the SyntaxHighlighter wordpress plugin and activate it. Visit :

http://wordpress.org/extend/plugins/syntaxhighlighter/

Once you are done with the activation proceed as above to post your programming language code.  Additionally , SyntaxHighlighter Plus is an enhanced version of the SyntaxHighlighter WordPress plugin for code syntax highlighting. 

http://wordpress.org/extend/plugins/syntaxhighlighter-plus/

One Response to “Source Code in WordPress”

  1. Frank Sun said

    Thanks pal, thats what I was looking for !!

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>