Including formatted sourcecode in WordPress
Posted by jpluimers 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:
- 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 - C# has
language
codecsharp
(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
kristobaldude said
Reblogged this on CodeSlayer2010 : Slaying Code 24/7!.
jpluimers said
Thanks!
kristobaldude said
No problem brother. It was a very good technical article and how-to involving tags.
Formatted sourcecode in WordPress: uses SyntaxHighlighter 3.0; complete list of supported languages « The Wiert Corner – irregular stream of Wiert stuff said
[…] the past I wrote a few blog posts on posting sourcecode in […]
Formatted sourcecode in WordPress now supports even more languages « The Wiert Corner – Jeroen Pluimers’ irregular stream of Wiert stuff said
[…] This is a follow up on the original article Including formatted sourcecode in WordPress « The Wiert Corner – Jeroen Pluimers’ irregular str…. […]
yet another update to TFS 2008 Folder Comparison Filter for both C# and Delphi projects « The Wiert Corner – Jeroen Pluimers’ irregular stream of Wiert stuff « The Wiert Corner – Jeroen Pluimers’ irregular stream of Wiert stuff said
[…] 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 […]
yet another update to TFS 2008 Folder Comparison Filter for both C# and Delphi projects « The Wiert Corner – Jeroen Pluimers’ irregular stream of Wiert stuff « The Wiert Corner – Jeroen Pluimers’ irregular stream of Wiert stuff said
[…] 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, […]
Posting source code at wordpress.com « Cambiatablog said
[…] Thanks to Joeren Plumier’s blog! […]