Inserting Code into Wordpress
Sunday, July 29th, 2007I’ve shed many tears over the years (I’m a poet, I just don’t know it) when trying to insert code samples into my Wordpress blog posts. Wordpress users who cover technical topics will have shared in my pain and will know exactly what I mean. I therefore feel obliged to let people know about a Wordpress plugin called Code Snippet which I recently discovered and installed. Code Snippet which is available for download at http://wordpress.org/extend/plugins/codesnippet-20/ enables bloggers to post color highlighted code (with optional line numbering) in their posts without fear of it being mangled or hidden by Wordpress. It runs off the GeSHi engine which is generic syntax highlighter which supports a tonne of programming and markup languages.
The installation of Code Snippet is extremely easy. You basically just need to upzip the archive to your desktop, upload it to the wp-content/plugins folder of your overall Wordpress installation folder and then activate it from the ‘Plugins’ tab from within Site Admin. To actually use the plugin you wrap code in code blocks illustrated by the below image.

You replace the value of the lang attribute with the language your code is written in such as HTML or c#. Below is an example of some PHP code displayed via Code Snippet.
-
$ufun = “$dfunction”;
-
switch ($ufun) {
-
case $ufun=“Edit”:
-
//go to Spoono
-
//Header ("Location: ./editor.php?filename=$filename&ffunction=$ffunction");
-
include(“editor.php”);
-
break;
-
-
case $ufun=“dDelete”:
-
echo “delete a dir”;
-
//Header ("Location: ./delete.php?filename=$filename&ffunction=$ffunction");
-
include(“delete.php”);
-
break;
-
-
case $ufun=“dRename”:
-
//echo "Rename was selected";
-
include(“rename.php”);
-
break;
-
-
case $ufun=“dCopy”:
-
//echo "Copy was selected";
-
include(“copy.php”);
-
break;
-
-
case $ufun=“dMove”:
-
//echo "Move was selected";
-
include(“move.php”);
-
break;
-
-
case $ufun=“dDownload”:
-
//echo "Download was selected";
-
include(“download.php”);
-
break;
-
-
case $ufun=“dOpen”:
-
//echo "Download was selected";
-
include(“filemanager.php”);
-
break;
-
-
default:
-
echo “You should not be here”;
-
}




