I’m using Ryan McGeary‘s excellent WP-Syntax plugin for syntax highlighting of code in WordPress. [It is now maintained by Steve Zahm.]
Update [7 Apr 2014]: I’m, uh, no longer using Ryan’s WP-Syntax plugin… I switched to Crayon Syntax Highlighter so I could have more control over the layout. The examples below are using Crayon now.
Without the plugin, simply using the <code> tag, code looks like this:
/* Hello World program */
#include <stdio.h>
int main( int argc, char *argv[] ) { printf("Hello World");
return 0; }
With the WP-Syntax plugin, it is formatted to make it much more readable:
1 2 3 4 5 6 7 8 9 10 |
/* Hello World program */ #include <stdio.h> int main( int argc, char *argv[] ) { printf("Hello World"); return 0; } |
One problem with the plugin though is that the CSS style sheet for the plugin is being included after some external Javascript in the head element of the HTML document. This prevents some browsers from loading the CSS in parallel which can delay loading of the page. A good way to catch these kinds of things is to use Google’s Page Speed plugin.