AKA Marketing.com Logo            VISIT THE BLOG            

Blogged thoughts, is our web blog. Expect views, opinion, rants and tirades about everything and anything 

« Home / Forums »        

Subscribe to our SEO / IT related blog by entering your email address below

Blogged thoughts

| by the www.akamarketing.com team



Inserting Code into Wordpress

I’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.

Code Snippet Code Blocks

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.

  1. $ufun = “$dfunction”;
  2. switch ($ufun) {
  3.  case $ufun=“Edit”:
  4.  //go to Spoono
  5.     //Header ("Location: ./editor.php?filename=$filename&ffunction=$ffunction");
  6.  include(“editor.php”);
  7.  break;
  8.  
  9.  case $ufun=“dDelete”:
  10.  echo “delete a dir”;
  11.  //Header ("Location: ./delete.php?filename=$filename&ffunction=$ffunction");
  12.  include(“delete.php”);
  13.  break;
  14.  
  15.  case $ufun=“dRename”:
  16.  //echo "Rename was selected";
  17.  include(“rename.php”);
  18.  break;
  19.  
  20.  case $ufun=“dCopy”:
  21.  //echo "Copy was selected";
  22.  include(“copy.php”);
  23.  break;
  24.  
  25.  case $ufun=“dMove”:
  26.  //echo "Move was selected";
  27.  include(“move.php”);
  28.  break;
  29.  
  30.     case $ufun=“dDownload”:
  31.  //echo "Download was selected";
  32.  include(“download.php”);
  33.  break;
  34.  
  35.  case $ufun=“dOpen”:
  36.  //echo "Download was selected";
  37.  include(“filemanager.php”);
  38.  break;
  39.  
  40.  default:
  41.  echo “You should not be here”;
  42.  }
One Comment on “Inserting Code into Wordpress”
1| Rolica said,

Nice! Will have to check it out. Does it allow multiple snippets on the same page though? hmmmmm, investigation needed I think. Thanks for posting.

Leave a Comment
Name:
Email:
Website:
 
HOME | ABOUT US | CONTACT US | SITEMAP | GOOGLE SITE SEARCH | TOP
12 Lorcan Crescent, Santry, Dublin 9, Ireland +353 87 9807629