WordPress and displaying code snippets in blogs

I’m having real problems displaying code snippets in WordPress. I’ve done a search for a possible pluggin to solve the problem and I’ve come across a plugin called, surprising enough Code Snippet. I’m going to install it and see how good it is.

I’ve had to change the CSS thats supplied with the code snippet pluggin from:
[code lang=”css”]border: 1px solid #ccc;
background: #eee;
padding: 5px;margin:10px;[/code]

to:

[code lang=”css”] font: 1.1em ‘Courier New’, Courier, Fixed;
border: 1px dotted #ddd;
margin: 15px 30px 0 10px;
padding: 5px;
background: #666666;
color: #ffcc66;
display: block; [/code]

As you can see it doesn’t look too bad, I’ll continue to use it and with luck won’t find any problems with it. Going to have to change all the rest of the blogs that have code in them to match this one. Just about to go through the rest of the code blogs and change the format a little.

Supported languages
Supported languages are

  • Actionscript
  • ADA
  • Apache Log
  • ASM
  • ASP
  • Bash
  • C
  • C for Macs
  • C#
  • C++
  • CAD DCL
  • CadLisp
  • CSS
  • Delphi
  • HTML
  • Java
  • Javascript
  • Lisp
  • Lua
  • Microprocessor ASM
  • NSIS
  • Objective C
  • OpenOffice BASIC
  • Oracle 8 SQL
  • Pascal
  • Perl
  • PHP
  • Python
  • Q(uick)BASIC
  • Smarty
  • SQL
  • VB.NET
  • Visual BASIC
  • Visual Fox Pro
  • XML.

Installation

  • copy archive to wp-content/plugins/ directory under your WordPress installation path
  • extract the zip file
  • when extracted properly you should have following directory structure: /wp-content/plugins/codesnippet

Plugin will not work if extracted or copied in diffrent directory.

Usage
To insert code into post, “code” tag is used with lang attribute.
Example: [ code lang=”php” ] < ?php echo $x ?> [ /code ]

Leave a Reply