Rhyous

November 1, 2009

How to post code in a wordpress blog so it maintains its formatting?

Filed under: Uncategorized — J. Abram barneck @ 10:42 pm

Hey all,

This was really easy to figure out, since there is a nice WordPress discussion about it here:
http://en.support.wordpress.com/code/

So a quick example:

So if you want your code to show up in your post and be nicely formatted and colored, similar to how it is in your favorite IDE, then put your code in between the following lines:

[sourcecode language=”cpp”]
int main()
{
    //Code
}
[/sourcecode]

It looks like this:

int main()
{
	//Code
}

Put your cursor over the code and check out the top right icons that appear. You can simply click an icon to open the source in a text editor or copy the source to your clipboard.

By the way, you must have the “language=” tag and you must use one of the following short names for the code language:

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

1 Comment »


RSS feed for comments on this post. TrackBack URI

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

Blog at WordPress.com.

%d bloggers like this: