Posting code in Wordpress
Like I said in the previous post, posting code inside Wordpress is a huge pain.
But I’ve found some tools that make it somewhat easier. Still stinks, just not as badly.
First thing you’ll want is the SyntaxHighlighter set of Javascript files from Google. Get them here as a RAR file. Under your blog’s directory, create a scripts directory and copy the .js files into it.
Next, get the SyntaxHighlighter plugin for Wordpress, which is found here. Unzip this, and copy the top-level folder and all child folders & files to your wp-content\plugins directory (you should now have a new folder in there named SyntaxHighlighter). Be aware that some of the files are text, some are binary, so make sure your FTP tool can tell the difference.
You will need to modify your header.php file from your theme. If you’re using the classic theme like me, this will be found at: wp-content\themes\classic. Your hosting provider may give you a way to edit this file online - mine does and it didn’t work. I had to download the file and make changes locally before re-uploading it. Insert the needed Script tags after the meta tag, but before the style tag. For the languages I will be writing, I added this block:
</p> <p><script src="/blog/scripts/shCore.js" type="text/javascript"></script><br /> <script src="/blog/scripts/shBrushCSharp.js" type="text/javascript"></script><br /> <script src="/blog/scripts/shBrushSql.js" type="text/javascript"></script><br /> <script src="/blog/scripts/shBrushVb.js" type="text/javascript"></script><br /> <script src="/blog/scripts/shBrushXml.js" type="text/javascript"></script><br />
And that should do it. I occasionally see some problems with leading spaces being eaten, and still haven’t found a good way to prevent/fix that.