Rhyous's 127.0.0.1 or ::1

November 1, 2009

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

Filed under: Wordpress — rhyous @ 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

1 Comment »

  1. [...] this is not for code posts. If you want to post code, see this post: How to post code in a wordpress blog so it maintains its formatting? Leave a [...]

    Pingback by How to make a nice quote field with a different background color in your WordPress blog post? « Rhyous's 127.0.0.1 or ::1 — November 1, 2009 @ 10:49 pm | Reply


RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.